# Angle between two planes

I have two triangles in 3d space which share 1 edge and I would like to determine if the angle between their normal vectors is "uphill" or "downhill". In other words, if you set one flat, would the angle between them be acute (uphill) or obtuse (downhill). Hopefully that makes sense.

So far I have the normal vectors of each triangle and have calculated the angle between the two triangles, however this angle is always >= 90 degrees.

Vector3 v1 = triangle1.Normal;
Vector3 v2 = triangle2.Normal;
float cosAngle = Vector3.Dot(v1, v2) / (v1.magnitude * v2.magnitude);
float degAngle = Mathf.Acos(cosAngle) * Mathf.Rad2Deg;


Is there a trick I am missing that lets me determine which direction this angle is in?

Here is my suggestion. You just need two vectors.

• in the first triangle, choose the normal vector, n1
• in the second triangle, choose a vector e2 from a point on the shared edge to the point not on the shared edge.

Then compute their dot product: n1 . e2. If it’s positive, the angle is acute. If it’s negative, the angle is obtuse. • Simpler than mine. Good suggestion! Dec 8, 2013 at 13:21
• Tried this and it works as well but is a little cheaper. Thanks both of you who answered! Dec 8, 2013 at 17:20

Consider the plane parallel to the normal of the first triangle and containing the shared edge. You can find a vector normal to this plane by crossing the shared edge with the normal of the first triangle. Then take the dot product of this vector with the second triangle normal - the sign of the dot product will tell you whether the shared edge forms a hill or a valley (with zero indicating the triangles are co-planar to within the available precision).

A picture should help explain why this is so. I'm visualizing it with quads because it's easier to show perspective, but it applies equally to triangles. Note that your signs may be reversed based on various choices of coordinate system/order of terms. • Thank you! I was able to get this working, however I had to play around with how I determined the shared edge. Two follow up questions. How do you decide which vertex to subtract from which to consistently create the shared edge? And can you explain why that dot product provides this? Dec 8, 2013 at 6:05
• I tried typing out a description but got snagged on definitions. So I figured a picture was worth a thousand words and just added a diagram above. ;) As for choosing the direction of the shared edge, imagine you're looking down on triangle 1, so its normal is pointed toward you. You want to consistently orient the edge clockwise about the normal. (Or, equivalently, counter-clockwise. Just pick one and stick with it. Flipping the direction will flip the blue arrow in the diagram above, making your results opposite) Dec 8, 2013 at 6:11
• Equivalently, you can cross normal1 with normal2, and check the dot product of the result with a vector along the shared edge. Dec 8, 2013 at 6:20