1
\$\begingroup\$

I don't understand the concept of Vector3.Angle in Unity.

Can someone please explain in detail how it computes the angle? From which two points is the angle measured? It would also be really awesome if you could provide some diagrams for me understand it more, visually.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ taking 2 vectors? it's just return acos(Vector.dot(vec1.normalised(), vec2.normalised())); \$\endgroup\$ Dec 7, 2014 at 2:02
  • \$\begingroup\$ The concept is to determine the angle between two directions. Or more succinctly, it's the concept of an angle itself. Can you elaborate about what you don't understand? Otherwise answers will consist of people guessing about how to help you, which makes for a bad question. \$\endgroup\$ Dec 7, 2014 at 2:04
  • \$\begingroup\$ I dont understand how it returns the angle value. As in like. From which two points is the angle measured. Is it possible to provide lines and the angle visually so i understand how it works ? \$\endgroup\$
    – JekasG
    Dec 7, 2014 at 5:51
  • \$\begingroup\$ I think that the over simplification of the Unity documentation is the confusing part, because it is actually getting the angle from the point of origin as you pointed out. Sometimes we just like to know how the API is doing the math. As I learn more, hopefully things like this will become more obvious. \$\endgroup\$
    – Jerry Walz
    Aug 20, 2022 at 12:25

2 Answers 2

3
\$\begingroup\$

There is some confusion as to what the parameters for Vector3.Angle() are. This function takes two Vector3 values. The documentation list them as Angle(Vector3 from, Vector3 to), which I think the confusion is coming from. It can be read as (and it should be) from here to there. If you are thinking of these parameters as points, this from here to there idea gives you a line. However, if you consider the parameters to be vectors, then what you are looking at is an angle. This is illustrated by the purple arc.

enter image description here

\$\endgroup\$
2
\$\begingroup\$

The lines you're looking for are those you get if you connect the point (0, 0, 0) with each of the two vectors. So, assuming that you have a vector from with coordinates (x1,y1,z1) and a second vector to with coordinates (x2,y2,z2) then Vector3.Angle(from, to) returns the angle between the red and the blue line:

enter image description here

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .