alienhelpdesk.com

angle math

This is just here so I don't forget ;)

(small characters here refer to angles, capitals to lengths of sides)


An oblique triangle

A triangle without a 90 degree angle

 math_oblique.gif

Python equivalents of the above math are for instance (untested):

A = math.sin(a) / (math.sin(b)/B)
B = math.sin(b) / (math.sin(c)/C)
C = math.sin(c) / (math.sin(a)/A)


A right angle triangle

A triangle with a single 90 degree angle (a in this case)

Python equivalents of the above math are for instance:

c = math.asin(C/A)
c = math.acos(A/C)
c = math.atan(C/B)
A = math.sqrt(B*B+C*C)

Remember soscastoa!


Finding the angle between two faces in Blender

Now this isn't really complicated.
Lets say you retrieve two faces from Blender's python API that are connected by an edge.
Lets call them face1 and face2 and face1.no retrieves the face normal of face1.

Then we can simply do the following to find the angle:

myAngle = Mathutils.AngleBetweenVecs(face1.no, face2.no)
The result though is only an angle between 0 and 90 degrees, to find out if that is positive or negative continue reading below.

Finding out whether the angle between two faces is convex or concave 

A lot of the time you also want to know whether the angle is concave or convex (positive or negative).

To get that we get the vector from the midpoint of face1 to the midpoint of face2.
The midpoint of a face is retrieved by getting face1.cent.
Then we get the dot product of the face normal of face1 and the vector we just retrieved.

 

In python that could be:

dotProduct = Mathutils.DotVecs(face1.no, (face2.cent - face1.cent))

The resulting dot product will be either positive or negative depending on whether the angle is concave or convex.