Programming and Graphics

(Kiana) #1

300 Introduction to C++ Programming and Graphics


0
0.2
0.4 0.6

0.8
1

0

0.5

1

−1

−0.5

0

0.5

1

y x

z

Figure 9.4.2 A three-dimensional plot generated byMatlabthrough C++ code.

//--- End the session:

cout << "Hit return to continue\n";
fgetc(stdin);

return 0;
}

Figure 9.4.2. shows the generated graphics display.


It is important to note that the C++ data matrixz[Nx+1][Ny+1]is
passed toMatlabas an (Ny+1)×(Nx+ 1) matrix using the statement:


mxArray * zz = mxCreateDoubleMatrix(Ny+1, Nx+1, mxREAL);

This is becauseMatlabstores the elements of a matrix by columns, whereas
C++ stores the elements of a matrix in rows.


Drawing a sphere


As a further application, we now discuss a code contained in the file
msphere.ccthat generates a sphere by plotting surface patches defined by az-
imuthal and meridional divisions:

Free download pdf