<< Chapter < Page | Chapter >> Page > |
Once the required vectors had been created in Listing 3 , there is nothing new in the code in Listing 4 . Therefore, no explanation of Listing 4 should be required beyond the comments embedded in the code.
The bottom line on the program named DotProd3D05
The bottom line is that because the methods in the game-math library named GM02 were designed to do most of the hard work, writing application programs such as DotProd3D05 using the game-math library is not difficult at all. You simply need to understand how to organize your code to accomplish the thingsthat you need to accomplish.
That concludes the explanation of the program named DotProd3D05 .
This program demonstrates how the dot product can be used to find vectors that are perpendicular to a given vector.
An infinite number of possibilities
Recall that you learned in the previous module that there are an infinite number of vectors that are perpendicular to a given vector in 3D. This programcomputes and displays normalized and scaled versions of six somewhat unique vectors of the infinite setof vectors that are perpendicular to a user specified vector.
The graphic output
The screen output from this program is shown in Figure 4 .
Figure 4 - Six (magenta) vectors that are perpendicular to a given (black) vector.
Output on the command-line screen
In addition to the graphic output shown in Figure 4 , the program also displays the values of three of the perpendicular vectors on the command-linescreen along with the angle between the perpendicular vector and the user-specified vector. The angle should always be 90 degrees or very close to 90degrees if the program is working properly. The other three of the six perpendicular vectors are simply negated versions of the three for which thevalues are displayed.
Special case of one zero coordinate value
If the user specifies one of the coordinate values to be zero (or close to zero) , the program only computes and displays four of the possible vectors in order to avoid performing division by a near-zero value. In this case, theorientation of two of the vectors will overlay the orientation of the other two. Because the vectors are normalized to the same length and occupy the same space,you will only see two vectors instead of four. This is illustrated in Figure 5 where the value of the z-axis coordinate value was set to zero relative to thevalue used in Figure 4 .
Figure 5 - Screen output when one coordinate has a value of zero.
Special case of two coordinates with a value of zero
If the user specifies two of the coordinate values to be zero or close to zero, the program doesn't produce a valid result. Instead, it draws aperpendicular vector where all of the coordinate values are zero resulting in a magenta vector head at the origin. It also displays NaN (Not a Number) for the angle on the command line screen.
The graphical user interface
The GUI shown in Figure 4 is provided to allow the user to enter three double values that define a GM02.Vector3D object. The GUI also provides an OK button in addition to a 3D drawing area.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?