- If the value was 0 then the angle between the two vectors is 90°
- If the value is positive so greater than 0, then the angle between the two vectors is less than 90°
- If the value is negative so less than 0, then the angle between the two vectors is greater than 90°
Pseudo code
float DotProduct(Vector2 _vectorA, Vector2 _vectorB)
{
return _vectorA.x * _vectorB.x + _vectorA.y * _vectorB.y;
}
The dot product can be used for more though as using the dot product with the unit vectors of any two given vectors can result in the actual angle between the two vectors.
- First find the unit vector of both given vectors
- Calculate the dot product of the two unit vectors
- Use arc cosine (dot product) to calculate the angle in radians
- Convert angle to degrees if needed
Also the dot product of two vectors that are the same equals the length of the vector squared. This can be used for geometric calculations. Another side note if you have a unit vector and a non unit vector you can perform scalar projects, which returns the length of the extended unit vector (Unit Vector * Non Unit Vector).
No comments:
Post a Comment