Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

I watched the video regarding dot product https://www.youtube.com/watch?v=xlnkTEyAx7Q and try to sum up the result with the formula a.b = |a||b|Cosθ but I couldn’t get it. Please help to point out where the mistake. Consider two object a, at position (ax,0,az) and b, at position (bx,0,bz), from the built in function in the video, vector3.Normalize(b.position-a.position) would return the value of the unit vector/direction of b toward a.

since both lies at y=0, it as if 2 object lies at 2D plant x and z

so vector3.Normalize(b.position-a.position) should produce
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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 (ba) 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading