- Home /

# How Vector.Angle works internally in Unity?

Is it using the way this page shows? http://www.calculator.net/triangle-calculator.html

**Answer** by Bunny83
·
Jan 05, 2017 at 12:41 PM

Vector3.Angle does this:

```
public static float Angle(Vector3 from, Vector3 to)
{
return Mathf.Acos(Mathf.Clamp(Vector3.Dot(from.normalized, to.normalized), -1f, 1f)) * 57.29578f;
}
```

To break it further down:

Both vectors are normalized first. So their lengths is 1.0.

The dot product between two vectors is simply

`a.x*b.x + a.y*b.y + a.z*b.z`

This gives you a single float value.The dot product is also defined as

`|a| * |b| * cos(alpha)`

where`|a|`

is the length of vector a and "alpha" the angle between the two vectors.Since both vectors have a length of 1.0 the result of the dot product is just the cosine of the angle.

`Mathf.Clamp`

simply keeps the value in the range -1 to 1 to avoid errors as`Mathf.Acos`

only accepts values in that range.`Mathf.Acos`

calculates the "inverse" cosine in radians.The magic number

`57.29578f`

is just`180f / PI`

to convert radians to degree

Keep in mind that Vector3.Angle returns an angle in the range 0° to 180° as 180 is the largest possible angle between two vectors.

Thank you very much! But could you tell me where do you get the source code?

The source code is from UnityEngine.dll. And yes the clamp appears to be unnecessary.

And another question: The result of Vector.Dot should between -1 and 1 as the two parameters are already normalized, so why need the Mathf.Clamp operation?

Well, it's probably just an additional "safety net". Theoretically the value should never be larger than 1.0 but in some cases it might be due to rounding errors. Mathf.Acos is just a wrapper for Math.Acos and it will return NaN if the value is larger than 1 or smaller than -1. Even when it's just 1.0000001 larger.

**Answer** by mikelo
·
Jan 05, 2017 at 12:05 PM

Vector3.Angle returns the angle in degrees between two input vectors.

About the page you share. If you represent the triangle's sides with vectors, with this method you can get the angles on the corners.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Moving in a Arch 1 Answer

Raycast across angle? 3 Answers

Angle between player and rocket targetting player. 1 Answer

Orienting multiple objects on the same line 1 Answer

Finding Face Angle 0 Answers