Home > Mobile >  Why the algorithm for dot product return value different from the dot product in google?
Why the algorithm for dot product return value different from the dot product in google?

Time:03-08

I watched the video regarding dot product enter image description here

and consider object a facing(ax,0,az) direction then a.forward will produce

enter image description here

Lastly, vector3.Dot(a.forward,vector3.Normalize(b.position-a.position)) should produce

enter image description here

Try to compare the result in google a.b = |a||b|Cosθ

enter image description here

Both result entirely different. Please help me to understand these formula and correct my mistake

CodePudding user response:

The angle θ is the angle between the vectors a and b. This is important. And cos(θ) is the value which is shown in the video. But in your equations, you are finding the vector (b - a) and finding the angle between this and a. So your vector3.Dot(a.forward,vector3.Normalize(b.position-a.position)) does not equal cos(θ) but cos(the angle between a and b-a). And this is not what you want.

You should rather do vector3.Dot(vector3.Normalize(a),vector3.Normalize(b)) since this is the same as

(a/|a|).(b/|b|) = (a.b) / (|a| * |b|).

Your last formula is correct.

  • Related