Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find angle between faces from face normals

Tags:

geometry

3d

angle

I have some face normals and I need to calculate the angle between the faces they belong to. The problem I'm having is with finding angles between faces when the angle is greater than 180 - I can't figure out how to tell the difference between an angle of 45 and an angle of 315.

edit2: I have access to the obj file defining the model, what information would i need to differentiate between 45' and 315'? Also, I am building the (low-poly) models used, so I can guarantee no intersecting faces, etc.

edit:

ang = math.acos(dotproduct(v1, v2) / (length(v1) * length(v2)))

ang = math.degrees(ang)

ang = 360 - (ang + 180)
like image 539
pkinsky Avatar asked Mar 18 '11 16:03

pkinsky


1 Answers

Ensure that your normals are unit length (divide by their length if necessary). Then find the dot product.

dp = n1.x*n2.x + n1.y*n2.y + n1.z*n2.z

This will give a value in [-1 to 1].
If dp is negative, the angle is greater than 90 degrees.

To find the angle, use arc-cosine.

θ = acos(dp);

That will give you the value in radians. To convert to degrees, multiply by 180/pi.


Edit: Assume the faces are defined as polygons. If the faces are not co-planar, there must exist one point in each face's polygon definition that is not co-planar with the other polygon. Consider two triangles: if one edge is connected, they share two vertices but each have one un-shared vertex. I'll call these v1 and v2 associated respectively with normals n1 and n2. Find the vector from v1 to v2:

m = v2-v1

If the angle between m and n1 is greater than 90 [dotP(m,n1)<0] then the polygons face away from each other. If the angle is less than 90, the polygons are facing toward each other. If the angle is 90 degrees, then I think that the polygons are co-planar (or one of your chosen points is on the line of planar intersection or I've missed a case in my thinking).

like image 172
JCooper Avatar answered Sep 16 '22 18:09

JCooper