For details, see How to Use.
Plotting Arrays on a 3D Graph (Surface/Mesh Plot)
This VCSSL program plots coordinate values stored in arrays on a 3D graph. It's a short and simple sample code, suitable for modification or reuse.
» Related page: 3D Graph Plotting in Java
In the previous example, we looked at a method where coordinate values for a mesh were first written to a file and then plotted on a 3D graph. That approach is common in numerical computation, where coordinate values are output from a calculation program and plotted later by reading the file.
However, file I/O can take a noticeable amount of time, which becomes a bottleneck in cases such as animations. In such cases, a faster alternative is to store the coordinates in arrays and pass them directly to the graph software -- without going through files.
Sponsored Link
How to Use
Download and Extract
At first, click the "Download" button at the above of the title of this page by your PC (not smartphone). A ZIP file will be downloaded.
Then, please extract the ZIP file. On general environment (Windows®, major Linux distributions, etc.), you can extract the ZIP file by selecting "Extract All" and so on from right-clicking menu.
» If the extraction of the downloaded ZIP file is stopped with security warning messages...
Execute this Program
Next, open the extracted folder and execute this VCSSL program.
For Windows
Double-click the following batch file to execute:
For Linux, etc.
Execute "VCSSL.jar" on the command-line terminal as follows:
java -jar VCSSL.jar
» If the error message about non-availability of "java" command is output...
After Launching
When launched, the program starts the 3D graph software and plots a surface graph, overlaid with a mesh grid.
To change the plotted data, edit the part of the code where the coordinate arrays are populated (i.e., inside the "for" loops).
To adjust the brightness, lighting, or color intensity, open the 3D graph window and select Edit > Set Light from the menu bar.
Various other settings are also available. (You can also save settings to a file and load them from your program using the setGraph3DConfigurationFile function.)
Code
Now, let's walk through the code of this program. The code is written in VCSSL.
Full Code
Here's the complete code -- around 30 lines in total:
The overall flow is simple: the first half fills the arrays with coordinate values for the mesh grid, and the second half plots them on the graph.
First Part
Let's start from the top of the code:
The line "coding UTF-8;" specifies the character encoding of the program. It's not strictly required, but including it helps prevent character corruption.
The line import tool.Graph3D; loads the tool.Graph3D library, which is necessary for 3D graph plotting.
Preparing Sample Coordinate Arrays
Here's the part where the coordinate values are prepared and stored in arrays:
Here, "xData", "yData", and "zData" are 2D arrays storing the X, Y, and Z coordinates of mesh grid points, respectively. The two indices of each array correspond to the position of a grid point in the mesh.
Let's suppose the points are arranged like this:

In this case, the array index format for each coordinate array is:
In the code above, "yi" is the index for Y, and "xi" for X.
Note: You can also use the index order
-- either is fine.
In fact, the edges of the mesh don't even need to align with the X and Y axes. They can form skewed grids (like parallelograms) or even represent curved surfaces such as spheres (e.g., using longitude and latitude). The key is that the two indices represent the horizontal and vertical layout of the mesh in some logical way.
Plotting
Now let's look at the part that plots the prepared arrays on the 3D graph:
The newGraph3D() function launches the 3D graph software. Each time it's called, a new graph instance is created and assigned a unique ID number.
For example, if you launch multiple graph windows, they may be assigned IDs like Graph #12, #22, #101, and so on. In the code above, the returned ID is stored in the int variable "graph".
The setGraph3DData() function then sends the coordinate arrays to the specified graph instance using that ID. This allows you to control and update multiple graphs independently.
The last three lines set the plot options using setGraph3DOption(). By default, point plotting is enabled, but here it is turned off, and instead:
- Mesh plotting is enabled with "WITH_MESHES"
- Surface plotting is enabled with "WITH_MEMBRANES"
Note: Although the option name "WITH_MEMBRANES" is used in the code, this corresponds to what is commonly known as a surface plot. The term may be updated in future versions.
License
The license of this VCSSL / Vnano code (the file with the extension ".vcssl" / ".vnano") is CC0 (Public Domain), so you can customize / divert / redistribute this VCSSL code freely.
Also, if example code written in C/C++/Java are displayed/distributed on Code section of this page, they also are distributed under CC0, unless otherwise noted.
3D Graph Plotting Tool for Animating Data Loaded from Multiple Files |
|
![]() |
A simple tool which plots 3D animation graphs by loading multiple data files. |
2D Graph Plotting Tool for Animating Data Loaded from Multiple Files |
|
![]() |
A simple tool which plots 2D animation graphs by loading multiple data files. |
3D Graph Tool for Plotting & Animating Expressions of the Form of "z = f(x,y,t)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "z = f(x,y,t)" to the 3D graph, and plays it as animation. |
2D Graph Tool for Plotting & Animating Expressions of the Form of "y = f(x,t)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "y = f(x,t)" to the 2D graph, and plays it as animation. |
3D Graph Tool for Plotting & Animating Parametric Expressions of the Form of x(t), y(t), z(t) |
|
![]() |
A simple tool which plots parametric expressions (formulas) of the form of x(t), y(t), z(t) to the 3D graph, and plays it as animation. |
2D Graph Tool for Plotting & Animating Parametric Expressions of the Form of x(t) and y(t) |
|
![]() |
A simple tool which plots parametric expressions (formulas) of the form of x(t) and y(t) to the 2D graph, and plays it as animation. |
3D Graph Tool for Plotting Expressions of the Form of "z = f(x,y)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "z = f(x,y)" to the 3D graph. |
2D Graph Tool for Plotting Expressions of the Form of "y = f(x)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "y = f(x)" to the 2D graph. |
Animating a 3D Graph by Continuously Plotting Arrays (Surface/Mesh Plot) |
|
![]() |
Explains how to create 3D surface/mesh graph animations by updating arrays over time. |
Animating a 3D Graph by Continuously Plotting Arrays (Point/Line Plot) |
|
![]() |
Explains how to create 3D point/line graph animations by updating arrays over time. |
Animating a 2D Graph by Continuously Plotting Arrays |
|
![]() |
Explains how to create 2D graph animations by updating arrays over time. |
Plotting Arrays on a 3D Graph (Surface/Mesh Plot) |
|
![]() |
Explains how to plot coordinate data stored in an array on a 3D surface/mesh graph with sample code. |
Plotting a File on a 3D Graph (Surface/Mesh Plot) |
|
![]() |
Explains how to plot coordinate data from a file on a 3D surface/mesh graph with sample code. |
Plotting Arrays on a 3D Graph (Point/Line Graph) |
|
![]() |
Explains how to plot coordinate data stored in an array on a 3D graph with sample code. |
Plotting Arrays on a 2D Graph |
|
![]() |
Explains how to plot coordinate data stored in an array on a 2D graph with sample code. |
Plotting a File on a 3D Graph (Point/Line Graph) |
|
![]() |
Explains how to plot coordinate data from a file on a 3D graph with sample code. |
Plotting a File on a 2D Graph |
|
![]() |
Explains how to plot coordinate data from a file on a 2D graph with sample code. |