[ Prev | Index | Next ]
Japanese English
Now Loading...
Download
Please download on PC (not smartphone) and extract the ZIP file. Then double-click VCSSL.bat (batch file) to execute for Microsoft® Windows®, or execute VCSSL.jar (JAR file) on the command line for Linux® and other OSes.
For details, see How to Use.
You are free to use and modify this program and material, even for educational or commercial use. » Details

Plotting a File on a 3D Graph (Surface/Mesh Plot)

This VCSSL program plots the contents of a file containing coordinate values on a 3D graph. It's a short sample code, making it ideal as a starting point for modification or reuse.

» Related page: 3D Graph Plotting in Java

- Table of Contents -

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.

If you are using Windows, right-click the ZIP file and choose "Properties" from the menu, and enable "Unblock" checkbox at the right-bottom (in the line of "Security") of the properties-window. Otherwise, when you extract the ZIP file or when you execute the software, security warning messages may pop up and the extraction/execution may fail.

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:

VCSSL__Double_Click_This_to_Execute.bat

For Linux, etc.

Execute "VCSSL.jar" on the command-line terminal as follows:

cd <extracted_folder>
java -jar VCSSL.jar

» If the error message about non-availability of "java" command is output...

After Launching

When executed, the program first writes some sample coordinate values to a file named "sample3d.txt", then launches the 3D graph software, and plots the file contents.

Graph Image

To change what's plotted, simply modify the part of the code that writes coordinate values into the file (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 even save those settings to a file and apply them later in your program using the setGraph3DConfigurationFile function.)

Code

Now, let's take a look at the code. This program is written in VCSSL.

Full Code

Here is the complete code. It's very short, around 30 lines:


coding UTF-8;

// Required to handle 3D graphs
import tool.Graph3D;


// Write sample coordinate data to file (WRITE_TSV means tab-separated format)
int file = open("sample3d.txt", WRITE_TSV);
for(int yi=0; yi<=10; yi++){
	for(int xi=0; xi<=10; xi++){
		float x = xi * 0.4 - 2.0; // from -2.0 to 2.0
		float y = yi * 0.4 - 2.0; // from -2.0 to 2.0
		float z = y*y - x*x;
		writeln(file, x, y, z); // Write "x y z" to a line
	}
	writeln(file, ""); // Insert a blank line to separate rows
}
close(file);


// Launch the 3D graph
int graph = newGraph3D();

// Plot the file on the 3D graph
setGraph3DFile(graph, "sample3d.txt");

// Set plot options
setGraph3DOption(graph, "WITH_POINTS", false);   // Disable point plot
setGraph3DOption(graph, "WITH_MESHES", true);    // Enable mesh plot
setGraph3DOption(graph, "WITH_MEMBRANES", true); // Enable surface plot
FileToMeshGraph3D.vcssl

As you can see, the program first writes out the coordinate values to a file, then plots them on a 3D graph.

First Part

Let's look at the beginning of the code:


coding UTF-8;

// Required to handle 3D graphs
import tool.Graph3D;
code/import.vcssl

The "coding UTF-8;" line specifies the character encoding of the program. While not mandatory, including it helps prevent character corruption.

The "import tool.Graph3D;" line loads the tool.Graph3D library, which is required for handling 3D graphs.

Writing the Coordinate File

Next is the part that writes the coordinate data to a file:


// Write sample coordinate data to file (WRITE_TSV means tab-separated format)
int file = open("sample3d.txt", WRITE_TSV);
for(int yi=0; yi<=10; yi++){
	for(int xi=0; xi<=10; xi++){
		float x = xi * 0.4 - 2.0; // from -2.0 to 2.0
		float y = yi * 0.4 - 2.0; // from -2.0 to 2.0
		float z = y*y - x*x;
		writeln(file, x, y, z); // Write "x y z" to a line
	}
	writeln(file, ""); // Insert a blank line to separate rows
}
close(file);
code/write.txt

This writes the coordinates in three-column format like this:

x1,1    y1,1    z1,1
x2,1    y2,1    z2,1
x3,1    y3,1    z3,1
c

Each line contains one point (x, y, z), separated by tabs.

(Note: If you change "WRITE_TSV" to "WRITE_CSV" in the open() function, the output format will be comma-separated instead of tab-separated.)

Imagine that (x1,1,y1,1,z1,1) is the coordinate of point P1,1, (x2,2,y2,2,z2,2) is P2,2, and so on -- all arranged on a grid like this:

The grid of points forms a mesh when connected. You can think of this as a surface mesh viewed from above -- each point corresponds to a vertex on the surface.

By writing all of these points into a file in the correct format, you provide enough data for the graph software to reconstruct and render the surface.

The order in which the points are written to the file follows a specific rule. It's easiest to understand through a visual diagram:

As shown by the red arrows, you first fix Y at one row, and write all the X-direction points from one end to the other.

Once a row is complete, insert a blank line and move one step in the Y-direction. Repeat this process until you've written all rows and reached the opposite Y-end.

Think of it like laying threads one row at a time to weave a surface.

This format is widely supported by graphing software. In the VCSSL environment, RINEARN Graph 3D is used for 3D plotting, and it supports this format as well. While it may seem a bit tricky at first, it's a convenient and efficient structure for generating data with code.

Other formats are also supported, so for more details, see the Coordinate File Format Guide for RINEARN Graph 3D.

Plotting

Finally, let's look at the part that plots the file data on the 3D graph:


// Launch the 3D graph
int graph = newGraph3D();

// Plot the file on the 3D graph
setGraph3DFile(graph, "sample3d.txt");

// Set plot options
setGraph3DOption(graph, "WITH_POINTS", false);   // Disable point plot
setGraph3DOption(graph, "WITH_MESHES", true);    // Enable mesh plot
setGraph3DOption(graph, "WITH_MEMBRANES", true); // Enable surface plotN
code/plot.txt

The newGraph3D() function launches the 3D graph software. Each time it's called, a new graph window is opened and assigned a unique ID number.

For example, if multiple graphs are launched, they might be assigned IDs like Graph #12, #22, #101, etc. Here, the returned ID is stored in the int variable "graph".

The setGraph3DFile() function then loads the file "sample3d.txt" into the specified graph using its ID.

The next three lines configure the plot options using the setGraph3DOption() function. By default, point plotting is enabled, but here it is disabled, and instead:

  • Mesh plotting is enabled via "WITH_MESHES"
  • Surface plotting is enabled via "WITH_MEMBRANES"
Note: Although the option name "WITH_MEMBRANES" is currently used in the API, this corresponds to what is commonly called a surface plot. The term may be updated in future versions.

License

This VCSSL/Vnano code (files with the ".vcssl" or ".vnano" extensions) is released under the CC0 license, effectively placing it in the public domain. If any sample code in C, C++, or Java is included in this article, it is also released under the same terms. You are free to use, modify, or repurpose it as you wish.

* The distribution folder also includes the VCSSL runtime environment, so you can run the program immediately after downloading. The license for the runtime is included in the gLicenseh folder.
(In short, it can be used freely for both commercial and non-commercial purposes, but the developers take no responsibility for any consequences arising from its use.) For details on the files and licenses included in the distribution folder, please refer to "ReadMe.txt".

* The Vnano runtime environment is also available as open-source, so you can embed it in other software if needed. For more information, see here.


Author of This Article

Fumihiro Matsui
[ Founder of RINEARN, Doctor of Science (Physics), Applied Info Tech Engineer ]
Develops VCSSL, RINEARN Graph 3D and more. Also writes guides and articles.

Japanese English
[ Prev | Index | Next ]
3DGraphPlottingToolforAnimatingDataLoadedfromMultipleFiles

Asimpletoolwhichplots3Danimationgraphsbyloadingmultipledatafiles.
2DGraphPlottingToolforAnimatingDataLoadedfromMultipleFiles

Asimpletoolwhichplots2Danimationgraphsbyloadingmultipledatafiles.
3DGraphToolforPlotting&AnimatingExpressionsoftheFormof"z=f(x,y,t)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"z=f(x,y,t)"tothe3Dgraph,andplaysitasanimation.
2DGraphToolforPlotting&AnimatingExpressionsoftheFormof"y=f(x,t)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"y=f(x,t)"tothe2Dgraph,andplaysitasanimation.
3DGraphToolforPlotting&AnimatingParametricExpressionsoftheFormofx(t),y(t),z(t)

Asimpletoolwhichplotsparametricexpressions(formulas)oftheformofx(t),y(t),z(t)tothe3Dgraph,andplaysitasanimation.
2DGraphToolforPlotting&AnimatingParametricExpressionsoftheFormofx(t)andy(t)

Asimpletoolwhichplotsparametricexpressions(formulas)oftheformofx(t)andy(t)tothe2Dgraph,andplaysitasanimation.
3DGraphToolforPlottingExpressionsoftheFormof"z=f(x,y)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"z=f(x,y)"tothe3Dgraph.
2DGraphToolforPlottingExpressionsoftheFormof"y=f(x)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"y=f(x)"tothe2Dgraph.
Animatinga3DGraphbyContinuouslyPlottingArrays(Surface/MeshPlot)

Explainshowtocreate3Dsurface/meshgraphanimationsbyupdatingarraysovertime.
Animatinga3DGraphbyContinuouslyPlottingArrays(Point/LinePlot)

Explainshowtocreate3Dpoint/linegraphanimationsbyupdatingarraysovertime.
Animatinga2DGraphbyContinuouslyPlottingArrays

Explainshowtocreate2Dgraphanimationsbyupdatingarraysovertime.
PlottingArraysona3DGraph(Surface/MeshPlot)

Explainshowtoplotcoordinatedatastoredinanarrayona3Dsurface/meshgraphwithsamplecode.
PlottingaFileona3DGraph(Surface/MeshPlot)

Explainshowtoplotcoordinatedatafromafileona3Dsurface/meshgraphwithsamplecode.
PlottingArraysona3DGraph(Point/LineGraph)

Explainshowtoplotcoordinatedatastoredinanarrayona3Dgraphwithsamplecode.
PlottingArraysona2DGraph

Explainshowtoplotcoordinatedatastoredinanarrayona2Dgraphwithsamplecode.
PlottingaFileona3DGraph(Point/LineGraph)

Explainshowtoplotcoordinatedatafromafileona3Dgraphwithsamplecode.
PlottingaFileona2DGraph

Explainshowtoplotcoordinatedatafromafileona2Dgraphwithsamplecode.
Index
[ Prev | Index | Next ]
3DGraphPlottingToolforAnimatingDataLoadedfromMultipleFiles

Asimpletoolwhichplots3Danimationgraphsbyloadingmultipledatafiles.
2DGraphPlottingToolforAnimatingDataLoadedfromMultipleFiles

Asimpletoolwhichplots2Danimationgraphsbyloadingmultipledatafiles.
3DGraphToolforPlotting&AnimatingExpressionsoftheFormof"z=f(x,y,t)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"z=f(x,y,t)"tothe3Dgraph,andplaysitasanimation.
2DGraphToolforPlotting&AnimatingExpressionsoftheFormof"y=f(x,t)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"y=f(x,t)"tothe2Dgraph,andplaysitasanimation.
3DGraphToolforPlotting&AnimatingParametricExpressionsoftheFormofx(t),y(t),z(t)

Asimpletoolwhichplotsparametricexpressions(formulas)oftheformofx(t),y(t),z(t)tothe3Dgraph,andplaysitasanimation.
2DGraphToolforPlotting&AnimatingParametricExpressionsoftheFormofx(t)andy(t)

Asimpletoolwhichplotsparametricexpressions(formulas)oftheformofx(t)andy(t)tothe2Dgraph,andplaysitasanimation.
3DGraphToolforPlottingExpressionsoftheFormof"z=f(x,y)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"z=f(x,y)"tothe3Dgraph.
2DGraphToolforPlottingExpressionsoftheFormof"y=f(x)"

Asimpletoolwhichplotstheexpression(formula)oftheformof"y=f(x)"tothe2Dgraph.
Animatinga3DGraphbyContinuouslyPlottingArrays(Surface/MeshPlot)

Explainshowtocreate3Dsurface/meshgraphanimationsbyupdatingarraysovertime.
Animatinga3DGraphbyContinuouslyPlottingArrays(Point/LinePlot)

Explainshowtocreate3Dpoint/linegraphanimationsbyupdatingarraysovertime.
Animatinga2DGraphbyContinuouslyPlottingArrays

Explainshowtocreate2Dgraphanimationsbyupdatingarraysovertime.
PlottingArraysona3DGraph(Surface/MeshPlot)

Explainshowtoplotcoordinatedatastoredinanarrayona3Dsurface/meshgraphwithsamplecode.
PlottingaFileona3DGraph(Surface/MeshPlot)

Explainshowtoplotcoordinatedatafromafileona3Dsurface/meshgraphwithsamplecode.
PlottingArraysona3DGraph(Point/LineGraph)

Explainshowtoplotcoordinatedatastoredinanarrayona3Dgraphwithsamplecode.
PlottingArraysona2DGraph

Explainshowtoplotcoordinatedatastoredinanarrayona2Dgraphwithsamplecode.
PlottingaFileona3DGraph(Point/LineGraph)

Explainshowtoplotcoordinatedatafromafileona3Dgraphwithsamplecode.
PlottingaFileona2DGraph

Explainshowtoplotcoordinatedatafromafileona2Dgraphwithsamplecode.
News From RINEARN
* VCSSL is developed by RINEARN.

Exevalatorv2.4Released—MCPSupportAdded,NowUsableasanAICalculationTool
2025-11-15 - We'vereleasedExevalatorv2.4,ourexpression-evaluationlibrary.Startingwiththisversion,itsupportsMCP,makingitusableasacalculationtoolforAIassistants.

Exevalatorv2.3Released—NowUsablefromPython
2025-11-04 - We'vereleasedExevalatorv2.3.Startingwiththisversion,youcannowuseitfromPython!WithgrowingdemandaroundAItooldevelopmentinmind,wesharethedetailshere.

ExevalatorUpdated—EasyJapaneseLocalizationforErrorMessages
2025-10-31 - Exevalator2.2.2isout.YoucannowlocalizeerrormessagestoJapanesewithasimplecopy-and-paste,andwe'veincludedseveralbugfixesandminorparseradjustments.

InsideRINPnOnline:ArchitectureOverview
2025-10-22 - AninsidelookatthearchitectureoftherecentlylaunchedonlineversionoftheRINPnscientificcalculator.It'sopensource,soyoucanfreelymodifyandreuseittobuildyourownwebcalculator(maybe!).

MeetRINPnOnline:UsetheScientificCalculatorAnywhere,Instantly
2025-10-21 - RINPn,thefreescientificcalculator,nowhasanonlineversionyoucanuseinstantlyinyourbrowser—onbothPCandsmartphones.Readtheannouncementfordetails.

TheVCSSLSupportAIisHere!—RequiresaChatGPTPlusAccountforPracticalPerformance
2025-08-19 - AnewAIassistantfortheVCSSLprogramminglanguageisheretoansweryourquestionsandhelpwithcoding.ThisarticleexplainshowtouseitandshowcasesplentyofrealQ&Aandgeneratedcodeexamples.

EnglishDocumentationforOurSoftwareandVCSSLIsNowNearlyComplete
2025-06-30 - We'rehappytoannouncethatthelarge-scaleexpansionofourEnglishdocumentationwiththesupportofAI—aprojectthatbegantwoyearsago—hasnowreacheditsinitialtargetmilestone.

VCSSL3.4.52Released:EnhancedIntegrationwithExternalProgramsandMore
2025-05-25 - Thisupdateintroducesenhancementstotheexternalprogramintegrationfeatures(e.g.,forrunningC-languageexecutables).Severalotherimprovementsandfixesarealsoincluded.Detailsinside.