This post was first posted on my CSDN blog and is now synchronized to Jane’s book.

In my last blog, I talked about using vector orientation properties to solve problems. This blog post continues with a simple little example of how to apply the dot product properties of vectors to real game development.

Geometric definition of vector dot product

A two-dimensional space with two vectors U and V, an Angle of theta they ([0, PI]), the inner product is defined as the following variables: vector dot product formula: U, V = | U | | | V cosine theta, according to the formula can be back to the following five conclusions:

1. ** U *, V* > 0 is the vector **U** and **V** The included Angle between * is less than 90 degrees (acute Angle)* U *, V* < 0, the vector **U** and **V** The included Angle is greater than 90 degrees (obtuse Angle)* U *, VStar is equal to 0, the vector star*U** and **V*The included Angle between * is 90 degrees (perpendicular to each other) 4. ** U *, VStar is equal to 1, the vector star*U** and **V** in the same direction 5* U *, VStar is equal to minus 1, which is the vector star*U** and **V** in the opposite directionCopy the code

Other definitions, rules and applications of vector dot product interested friends can refer to Baidu Encyclopedia, here is no longer wordy. This blog post is about applying these five lessons to game development.

Application scenario of vector dot product

  1. Find the Angle between two vectors according to the vector dot product formula.
  2. According to conclusions 1 and 2, the Angle between two vectors can be determined to define the Angle between two vectors.
  3. According to conclusion 3, judge whether the two vectors are perpendicular.
  4. According to conclusions 4 and 5, the position can be determined. Determine whether one object is in front or behind another (or to the left or right).

How does the dot product tell if one object is in front of another or behind another? This is well explained in the book fundamentals of 3D Mathematics: Graphics and Game Development. Here is a quote from the book:





Since we can judge the front or the back, we can also judge the left or the right, but the choice of direction vectors is different, which is left to the reader to think about.


Statement: this paper reproduction and sharing, but please respect the author’s work achievement, reprint please indicate the source when sharing: www.cnblogs.com/davidsheh/p… .