<< Chapter < Page | Chapter >> Page > |
(Although I didn't do so in Figure 11 , I could have written three more equations that could be used to solve for x1, y1, and z1 if the given vectoris notated as x2, y2, and z2.)
No simple case
Unlike with 2D vectors, (to my knowledge) , there is no case that simply allows you to swap coordinate values and change the sign on one of themto produce a vector that is perpendicular to another vector. However, given the equations in Figure 11 , and given values for x1, y1, and z1, we can assume values for y2 and z2 and determine the value for x2 that will cause thetwo vectors to be perpendicular.
While this is a fairly tedious computation with a hand calculator, it is very easy to write Java code to perform the computation. Therefore, given a 3Dvector, it is fairly easy to write Java code that will compute an infinite number of vectors that are perpendicular to the given vector.
A pair of perpendicular 3D vectors
Figure 12 and Figure 13 each show a magenta 3D vector that is part of the infinite set of vectors that are all perpendicular to the black 3D vector.In Figure 12 , y1 was assumed to be equal to y2, and z1 was assumed to be equal to z2. For an x1 value of 25, a value of -125 was required to cause themagenta vector to be perpendicular to the black vector.
Figure 12 A pair of perpendicular 3D vectors.
Another pair of perpendicular 3D vectors
In Figure 13 , x1 was assumed to be equal to x2, and z1 was assumed to be equal to z2.
Figure 13 Another pair of perpendicular 3D vectors.
For a y1 value of 50, a y2 value of - 25 was required to cause the magenta vector to be perpendicular to the black vector.
The black vector didn't change
Note that the black vector is the same in Figure 12 and Figure 13 . However, the magenta vectors are different in Figure 12 and Figure 13 . They represent just two of the infinite set of vectors that are perpendicular tothe black vector. (They are two of the vectors in the infinite set of perpendicular vectors that are relatively easy to compute using program code.)
Computing the angle between two vectors
The fifth property in the previous list reads: The angle between two vectors is the same as the angle between normalized versions of the vectors, which is equal to the arc cosine of the dot product ofthe normalized vectors.
In other words, given two vectors, we can compute the angle between the two vectors by first normalizing each vector and then computing the dot product ofthe two normalized vectors.
(By normalizing, I mean to change the coordinate values such that the direction of the vector remains the same but thelength of the vector is converted to 1.0.)
The dot product is equal to the cosine of the angle. The actual angle can be obtained by using one ofthe methods of the Math class to compute the arc cosine of the value of the dot product.
Used to compute the output angle in the programs
This is the procedure that is used by the programs in this module to compute and display the angle between two vectors as illustrated by the contents of theoutput fields labeled Ang(deg) or Angle (deg) = in many of the images in this module.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?