- Home /

# How to calculate internal angles of a mesh triangle?

Hi Guys!

I'm trying to find the internal angles a, b and c of the triangle in the picture below. The red points form a triangle of a mesh. I know the Vector3 positions of the red points and the normal of the triangle, but I don't know how to work out the angles between these points. How do I do this?

My triangle is below:

**Answer** by IrishSenthil
·
Mar 02 at 04:03 AM

Hi Guys,

I figured it out. Here is my solution:

```
public static float GetVectorInternalAngle(Vector3 a, Vector3 b, Vector3 c)
{
double num = (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y) + (b.z - a.z) * (c.z - a.z);
double den = Math.Sqrt(Math.Pow((b.x - a.x), 2) + Math.Pow((b.y - a.y), 2) + Math.Pow((b.z - a.z), 2)) *
Math.Sqrt(Math.Pow((c.x - a.x), 2) + Math.Pow((c.y - a.y), 2) + Math.Pow((c.z - a.z), 2));
double angle = Math.Acos(num / den) * (180.0 / Math.PI);
return (float) angle;
}
```

**Answer** by Bunny83
·
Mar 02 at 05:09 AM

Well, you can simply use Unity's Vector3.Angle method like this:

```
public static float GetVectorInternalAngle(Vector3 a, Vector3 b, Vector3 c)
{
return Vector3.Angle(b-a, c-a);
}
```

Following is an explanation what's actually happening here. You can ignore the following unless you are interested what happens behind the scenes.

What we actually do here is calculate the two vectors that meet at point a. The Angle function simply calculates the dot product between the two vectors which is just multiplying the two vectors component wise and adding all values up to a single value. This value has the nice property that it's the product of the lengths of the two vectors multiplied by the cosine of the angle between them.

To actually get the angle we just have to divide that value by the lengths of both vectors. To calculate the length of a vector we just use the Pythagorean Theorem. Unity's Vector3 struct does this calculation for us with the "magnitude" property. Though since we have to divide through both vector lengths the Angle function calculates the product using only one square root for both lengths.

Once the value is divided by the lengths the remaining value represents the cosine of the angle we're looking for. Now we could simply use the arcus cosine function (Acos()). However due to floating point imprecisions the Angle function first clamps the value between -1 and 1 because the arcus cosine of a value smaller than -1 or greater than 1 is not defined and would result in a NaN (Not a Number) value.

In actual mathematics and computer science the trigonometric functions (sine, cosine, tangent, ...) do not work in degrees but in radians. A full "360°" turn equals 2*PI in radians. So a value of PI represents 180°. To convert the angle in radians to degree we just have to divide by PI and multiply by 180. Unity's Mathf class provides this as a precalculated factor "Mathf.Rad2Deg".

### 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

Mesh.triangles specification 1 Answer

Null Reference Exception Assigning Vertices to Mesh 0 Answers

UNITY4 all i see is the triangle/verts of objects 1 Answer

Lighting up all triangles between two points in a mesh? 1 Answer

Creating a mesh "outline" around gameobject messes up when the gameobject rotates... 3 Answers