- Home /

# How can I calculate the angle between two adjacent triangles in 3D? (for detecting concave or convex triangles)

Hi guys,

I am trying to calculate the angle between two triangles in 3D space. Let's assume that triangle one consists of three points

`P1=(x1,y1,z1), P2=(x2,y2,z2), and **P3=(x3,y3,z3).**`

Triangle two consists also of three points

`P1=(x1,y1,z1), P2=(x2,y2,z2), and **P3=(x4,y4,z4).**`

Thank you in advance!!

**Answer** by Bunny83
·
Feb 09 at 02:15 PM

Well, it's a bit tricky but possible. The easiest solution is to calculate the vector between the two triangle centers and calculate the dot product between that vector and the normal of one of the triangles.

To calculate the center of a triangle, just add up the 3 positions and divide the result by 3

```
Vector3 C1 = T1P1+T1P2+T1P3; // center triangle 1
Vector3 C2 = T2P1+T2P2+T2P3; // center triangle 2
Vector3 N1 = Vector3.Cross(T1P2 - T1P1, T1P3 - T1P1); // normal of triangle 1
Vector3 D = C2 - C1; // vector from triangle1 center to triangle2 center
if (Vector3.Dot(N1, D) < 0f)
{
// convex
// since "D" is behind the T1 plane
}
else
{
// concave
// since "D" is in front of the T1 plane
}
```

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

How to make proper yaw effects in 3D space exploration game? 1 Answer

FOV visual representation script. Rotation causes offset 1 Answer

Camera Movement and angles 2 Answers

Fetching triangles from a 3D Mesh 2 Answers

Create a Triangle Mesh. 0 Answers