<< Chapter < Page Chapter >> Page >

We concluded earlier that the length of each of these vectors is 141.42. This length is the squareroot of the dot product of the vector with itself. Squaring and rounding this length gives a dot product value of 20000, which matches the value shown inthe bottom left output field in Figure 6 .

Dot product of vectors with opposite orientations

Figure 7 illustrates the third property of the dot product given above : The dot product of two vectors having opposite orientations is the negative of the product of their lengths.

Figure 7 Dot product of vectors with opposite orientations.

Missing image.

The two vectors shown in Figure 7 have the same absolute coordinates as the two vectors shown in Figure 5 . However, the algebraic signs of the coordinates of the magenta vector in Figure 7 were reversed relative to Figure 4 , causing the magenta vector to point in the opposite direction from the black vector. (Note that the angle between the two vectors, as reported by the program is zero degrees in Figure 5 and is 180 degrees in Figure 7 .)

The point here is that the dot product of the two vectors in Figure 7 is the negative of the dot product of the two vectors in Figure 5 . This property will be used in another program in the second part of this two-part miniseriesto achieve the back-face culling shown in Figure 1 .

The computational simplicity of the vector dot product

If you have studied the Kjell tutorial through Chapter 10, Angle between 3D Vectors you have learned that the dot product of two vectors can be computed as the sum of products of the corresponding x, y, and z components ofthe two vectors. In particular, in the 2D case , the dot product is given by:

2D dot product = x1*x2 + y1*y2

Similarly, in the 3D case , the dot product is given by:

3D dot product = x1*x2 + y1*y2 + z1*z2

Note that these two formulations don't require the program to know anything about the angle between the two vectors, as is the case in the earlie r definition.

The dot product of perpendicular vectors in 2D

The dot product has many uses in game programming, not the least of which is determining if two vectors are perpendicular.

Figure 8 illustrates the fourth property in the above list : The dot product of perpendicular vectors is zero . This is an extremely important property in that it allows game programs to easily determine if two vectorsare perpendicular. I will begin with a 2D discussion because the topic of perpendicularly of vectors is less complicated in 2D than in 3D .

Figure 8 The dot product of perpendicular vectors in 2D.

Missing image.

By eyeballing Figure 8 , you can see that the magenta vector is probably perpendicular to the black vector. Looking at the output fields at thebottom left and the bottom right in Figure 8 , you will see that the dot product of the two vectors is zero and the angle between the two vectors is 90 degrees.

Restating the perpendicularity property

Most of us learned in our earlier mathematics classes that the angle between perpendicular lines is 90 degrees. Therefore, the angle betweenperpendicular vectors must be 90 degrees. (See a definition of perpendicularity .)

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