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!!
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
}