Dot Product: Difference between revisions
m
Rename images to meaningful names
(Updated the page. TODO: update the explanation.) |
-u ndefined- (talk | contribs) m (Rename images to meaningful names) |
||
Line 38: | Line 38: | ||
== Example == | == Example == | ||
=== Finding its cosine angle === | |||
The dot product of two [[Normalize|unit vector]]s outputs the cosine of the angle between those two vectors. If our two inputs aren't unit vectors, we can find the cosine with two methods: | The dot product of two [[Normalize|unit vector]]s outputs the cosine of the angle between those two vectors. If our two inputs aren't unit vectors, we can find the cosine with two methods: | ||
Line 43: | Line 45: | ||
* Get the output of the dot product and divide it by the product of the two input vectors' length. | * Get the output of the dot product and divide it by the product of the two input vectors' length. | ||
{{Image|Dot Product cosine angle a.jpg}} | |||
To find the angle, we then use the inverse cosine function: | To find the angle, we then use the [[Break Rotation#Example|inverse cosine]] function: | ||
{{Image|Dot Product cosine angle b.jpg}} | |||
=== Object on sight === | |||
Here is another example, there is a guard facing a direction with a FOV of 90° (highlighted in green) and a ninja sneaking up on him. How can we check if the ninja is on sight? | Here is another example, there is a guard facing a direction with a FOV of 90° (highlighted in green) and a ninja sneaking up on him. How can we check if the ninja is on sight? | ||
{{Image|Dot product on sight a.jpg}} | |||
The first input for the dot product is the direction that the guard is facing, the second input is the vector from the guard's position to the ninja's position. Then we compare the cosine of the angle formed by those two vector with the cosine of half the FOV: | The first input for the dot product is the direction that the guard is facing, the second input is the vector from the guard's position to the ninja's position. Then we compare the cosine of the angle formed by those two vector with the cosine of half the FOV: | ||
{{Image|Dot product on sight b.jpg}} | |||
Let me explain the script: | Let me explain the script: | ||
Line 62: | Line 66: | ||
We don't have to normalize because the vector we rotated (0, 0, 1) already has a length of one. | We don't have to normalize because the vector we rotated (0, 0, 1) already has a length of one. | ||
* Finally after we get the dot product, check if its less than the cosine of half the FOV (half because the direction of the guard sits in the middle between the two edges of the FOV). If true, then the ninja is in sight, otherwise the ninja is still safe. | * Finally after we get the dot product, check if its less than the cosine of half the FOV (half because the direction of the guard sits in the middle between the two edges of the FOV). If true, then the ninja is in sight, otherwise the ninja is still safe. | ||
[[Category:Blocks]] | [[Category:Blocks]] |