<< Chapter < Page Chapter >> Page >

Although the actual code in Listing 2 should be familiar to you, the application may be new. The important thing to note is that the projectiononto each of the three planes in Listing 2 is accomplished by setting one of the coordinate values to zero for each projection. For example, in order to project the vector onto the XY plane, the value for the z-axis coordinate is set to zero as shown in Listing 2 .

Create and draw vectors

Listing 3 uses the ColMatrix3D objects created in Listing 1 and Listing 2 to create and draw vectors based on those ColMatrix3D objects.

Listing 3 . Create and draw vectors.
//Use the ColMatrix3D objects to create Vector3D // objects representing the user-specified vector and// each of the axes. GM02.Vector3D vecA = new GM02.Vector3D(matrixA);GM02.Vector3D vecX = new GM02.Vector3D(matrixX); GM02.Vector3D vecY = new GM02.Vector3D(matrixY);GM02.Vector3D vecZ = new GM02.Vector3D(matrixZ);//Create Vector3D objects that represent the // projection of the user-specified vector on each of// the planes. GM02.Vector3D vecXY = new GM02.Vector3D(matrixXY);GM02.Vector3D vecYZ = new GM02.Vector3D(matrixYZ); GM02.Vector3D vecZX = new GM02.Vector3D(matrixZX);//Draw the projection of the user specified vector on// each of the three planes. g2D.setColor(Color.MAGENTA);vecXY.draw(g2D,new GM02.Point3D( new GM02.ColMatrix3D(0,0,0)));vecYZ.draw(g2D,new GM02.Point3D( new GM02.ColMatrix3D(0,0,0)));vecZX.draw(g2D,new GM02.Point3D( new GM02.ColMatrix3D(0,0,0)));//Draw the user-specified vector with its tail at the// origin. g2D.setColor(Color.BLACK);vecA.draw(g2D,new GM02.Point3D( new GM02.ColMatrix3D(0,0,0)));

Once the ColMatrix3D objects have been created to serve each specific purpose, there is nothing new in Listing 3 . Therefore, no explanation of the code beyond the embedded comments should be necessary.

Compute and display the nine angles

Listing 4 calls the angle method of the GM02.Vector3D class nine times in succession, using references to the vectors created in Listing 3 , to compute and display the nine angle values shown in Figure 3 .

Listing 4 . Compute and display the nine angles.

//Compute and display the angle relative to the // x-axis.double angle = vecA.angle(vecX); angleX.setText("" + prepareForDisplay(angle));//Compute and display the angle relative to the // y-axis.angle = vecA.angle(vecY); angleY.setText("" + prepareForDisplay(angle));//Compute and display the angle relative to the// z-axis. angle = vecA.angle(vecZ);angleZ.setText("" + prepareForDisplay(angle));//Compute and display the angle relative to the// XY plane angle = vecA.angle(vecXY);angleXY.setText("" + prepareForDisplay(angle));//Compute and display the angle relative to the // YZ planeangle = vecA.angle(vecYZ); angleYZ.setText("" + prepareForDisplay(angle));//Compute and display the angle relative to the// ZX plane angle = vecA.angle(vecZX);angleZX.setText("" + prepareForDisplay(angle));//Compute and display the angle of the projection onto// the XY plane relative to the x-axis angle = vecXY.angle(vecX);anglePX.setText("" + prepareForDisplay(angle));//Compute and display the angle of the projection onto // the YZ plane relative to the y-axisangle = vecYZ.angle(vecY); anglePY.setText("" + prepareForDisplay(angle));//Compute and display the angle of the projection onto// the ZX plane relative to the z-axis angle = vecZX.angle(vecZ);anglePZ.setText("" + prepareForDisplay(angle));myCanvas.repaint();//Copy off-screen image to canvas.}//end actionPerformed

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask