Calculating angles between two adjacent triangles/polygons

Given a Mesh instance, I’m looking to inspect 2 adjacent triangular polygons and determine the angle they intersect/are adjacent at.

Once I know the indexes of the 2 triangles that I want to run this analysis on, I think I can get their Vector3f data like so (but please correct me if I’m wrong!):

// Get indices of two triangles. They will be adjacent/touching each other.
int t1Index = getSomehow("t1");
int t2Index = getSomehow("t2");

Vector3f t1v1, t1v2, t1v3, t2v1, t2v2, t2v2;
t1v1 = new Vector3f();
t1v2 = new Vector3f();
t1v3 = new Vector3f();
t2v1 = new Vector3f();
t2v2 = new Vector3f();
t2v3 = new Vector3f();

Mesh mesh = getMesh(); // Get it somehow

// Populate t1 and t2's vector data.
mesh.getTriangle(t1Index, t1v1, t1v2, t1v3);
mesh.getTriangle(t2Index, t2v1, t2v2, t2v3);

// Calculate the angle at which they intersect (touch each other at).
// TODO: ???

Are there any “utils” classes/methods that might help me with this calculation? Or any known formulas that I could just implement myself? Thanks!

If you mean what I think you mean… extrapolating because I’m only guessing why you might want this.

Get the triangle normals.

Calculate the dot product between them.

Hi @pspeed - in my simple game, users can inspect a mesh/model, select any two touching polygons, and I want to display the angle at which they intersect at. This might seem strange but is a very important aspect of the game!

For instance, take these two adjacent/touching triangles:

triangles

In this case, t1 = (A,B,D) and t2 = (A,C,D).

Perhaps these two triangles touch each other at a 0° angle, in which case they would form a plane with each other. Or perhaps they touch at 45°, or 90°, etc.

I need to calculate this angle (at which they touch each other).

Will your suggestion to calculate the dot product between them accomplish this? Thanks!

Yes, if by “angle between them” you mean the angle that the triangles face… which given your ‘plane’ description sounds right.

normal1.dot(normal2) = 1
…if they are exactly on the same plane. (check for a small epsilon to account for floating point rounding errors)

1 Like

Awesome - thanks again!