- Projection onto the XY plane relative to the x-axis, displayed with the label Angle PX .
- Projection onto the YZ plane relative to the y-axis, displayed with the label Angle PY .
- Projection onto the ZX plane relative to the z-axis, displayed with the label Angle PZ .
The graphical user interface
All angles are reported as positive angles in degrees. As you can see in Figure 3 , a GUI is provided that allows the user to enter three double values that define a GM02.Vector3D object. The GUI also provides an OK button as well as nine text fields that are used to display the computed resultsdescribed above. In addition, the GUI provides a 3D drawing area.
When the user clicks the OK button, the program draws the user-specified vector in black with the tail located at the origin in 3D space.It also draws the projection of that vector in magenta on each of the XY , YZ , AND ZX planes.
Very similar to previously-explained code
Much of the code in this program is very similar to code that I have explained in previous modules. I won't repeat those explanations here. Most ofthe new code is contained in the method named actionPerformed , so I will explain the code in that method. A complete listing of this program is providedin Listing 10 near the end of the module.
Beginning of the actionPerformed method in the program named DotProd3D05
Listing 1 shows the beginning of the actionPerformed method. This method is called to respond to a click on the OK button shown in Figure 3 .
Listing 1 . Beginning of the actionPerformed method in the program named DotProd3D05. |
---|
public void actionPerformed(ActionEvent e){//Erase the off-screen image and draw the axes.
setCoordinateFrame(g2D);//Create one ColMatrix3D object based on the user// input values.
GM02.ColMatrix3D matrixA = new GM02.ColMatrix3D(Double.parseDouble(vecX.getText()),
Double.parseDouble(vecY.getText()),Double.parseDouble(vecZ.getText()));//Create ColMatrix3D objects that represent each of
// the three axes.GM02.ColMatrix3D matrixX =
new GM02.ColMatrix3D(1,0,0);GM02.ColMatrix3D matrixY =
new GM02.ColMatrix3D(0,1,0);GM02.ColMatrix3D matrixZ =
new GM02.ColMatrix3D(0,0,1); |
You have seen code similar to that in Listing 1 many times before. Therefore, this code should not require further explanation beyond theembedded comments.
Create ColMatrix3D objects that represent projections
Listing 2 creates ColMatrix3D objects that represent the projection of the user-specified vector onto each of the three planes.
Listing 2 . Create ColMatrix3D objects that represent projections. |
---|
GM02.ColMatrix3D matrixXY = new GM02.ColMatrix3D(
Double.parseDouble(vecX.getText()),Double.parseDouble(vecY.getText()),
0);GM02.ColMatrix3D matrixYZ = new GM02.ColMatrix3D(0,
Double.parseDouble(vecY.getText()),
Double.parseDouble(vecZ.getText()));GM02.ColMatrix3D matrixZX = new GM02.ColMatrix3D(Double.parseDouble(vecX.getText()),
0,Double.parseDouble(vecZ.getText())); |