coding UTF-8; import Math; import Text; import GUI; import File; import tool.Graph3D; /** The default value of the expression z(x,y) to plot graph */ const string DEFAULT_Z_EXPRESSION = "sin(2*x) + cos(2*y)"; /** The default value of the maximum value of the x-range of the graph. */ const string DEFAULT_X_MAX = "1.0"; /** The default value of the minimum value of the x-range of the graph. */ const string DEFAULT_X_MIN = "-1.0"; /** The default value of the number of the point toward x-direction of the mesh. */ const string DEFAULT_X_N = "80"; /** The default value of the maximum value of the y-range of the graph. */ const string DEFAULT_Y_MAX = "1.0"; /** The default value of the minimum value of the y-range of the graph. */ const string DEFAULT_Y_MIN = "-1.0"; /** The default value of the number of the point toward y-direction of the mesh. */ const string DEFAULT_Y_N = "80"; // Followings are variables to store IDs of the graph and GUI components. /** Stores the ID of the graph. **/ int graph = NULL; /** Stores the ID of the input-window. **/ int window = NULL; /** Stores the ID of the text-field of the expression z(x,y). **/ int expressionField = NULL; /** Stores the ID of the text-field of the maximum value of x-range. **/ int xMaxField = NULL; /** Stores the ID of the text-field of the minimum value of x-range. **/ int xMinField = NULL; /** Stores the value of the number of the point toward x-direction of the mesh. */ int xNField = NULL; /** Stores the ID of the text-field of the maximum value of y-range. **/ int yMaxField = NULL; /** Stores the ID of the text-field of the minimum value of y-range. **/ int yMinField = NULL; /** Stores the value of the number of the point toward y-direction of the mesh. */ int yNField = NULL; /** Stores the ID of the PLOT button. **/ int plotButton = NULL; /** Stores the ID of the CLEAR button. **/ int clearButton = NULL; /** Stores the ID of the EXPORT button. **/ int exportButton = NULL; /** Stores the ID of the EXIT button. **/ int exitButton = NULL; /** * Invoked automatically when this program have started. */ void main(){ // Set the console window invisible because it is not necessary for GUI program. hide(); // Create (or get from the system) a 3D graph window. graph = getGraph3D(); // Set the size and the location of the graph-window. setGraph3DLocation(graph, 350, 0); setGraph3DSize(graph, 720, 600); // Set options of the graph setGraph3DOption( graph, "WITH_POINTS", false ); setGraph3DOption( graph, "WITH_LINES", false ); setGraph3DOption( graph, "WITH_MEMBRANES", true ); setGraph3DOption( graph, "WITH_MESHES", false ); // Create and launch the input-window. createInputWindow(); // If you want to read processings after when the user click PLOT button, // see "onButtonClick" function at near the bottom of this code. } /** * Plots the expression to the 3D graph. * * @param zExpression The expression of z(x,y). * @param xMin The minimum value of x-range. * @param xMax The maximum value of x-range. * @param xN The number of points toward x-direction of the mesh. * @param xMin The minimum value of y-range. * @param xMax The maximum value of y-range. * @param yN The number of points toward y-direction of the mesh. */ void plotGraph( string zExpression, double xMin, double xMax, int xN, double yMin, double yMax, int yN ){ // Arrays storing vertices data to transfer the graph. double xArray[yN][xN]; double yArray[yN][xN]; double zArray[yN][xN]; // coordinate variables of a point. double x; double y; double z; // Check the syntax of the expression z(x,y). if( !evaluable(zExpression, 0.0) ){ alert("The form of the expression of \"z(x,y)\" is wrong."); return; } // Store coordinate values to arrays at lattice points // (xN-1 and yN-1 equally divided points of the x-range and y-range) float dx = (xMax-xMin)/(xN-1); float dy = (yMax-yMin)/(yN-1); for( int xi=0; xi