# How to find out the angle of a face in script

I have an object here with 2 faces (front and back) perpendicular to the floor and perfectly aligned with front ortho, then a number of smaller faces on all sides.

In front ortho, it looks like this

From the side, it looks like this

I would like to use a script to get the angle of each side face, and then rotate it according to what angle it’s originally at.

The angle should be the angle between the face and the floor. Please share your advice on how I could go about this, thanks in advance

I think that the rotation manipulates vertices' location, so my option would be to check vertices' locations and their alignment correspondingly to the axes.

Example 1: (align to the X-axis) (View from the top) Here I picked 2 vertices of the face (V1 and V2)
A and B angles between the V1-V2 Edge and blue lines

Simply put:
if we want the V1-V2 Edge to be perpendicular to the X-axis, we should rotate it with B angle degrees;

if parallel, then with A angle degrees.

The same can be implemented correspondingly to other axes

Getting angles:
As long as we know V1 and V2 Location values, angles A and B can be calculated using sin.

As an example of aligning to the X-axis, here is what we can do:

This is the base method, any of the given info can be found on the internet including the formulas to use in the script.

• Thank you, I’ll have a look and come back to this. However if I manage to get the maths done, is bpy.ops.transform.rotate() the method I should be using? Or is there a more standard way Jun 14, 2022 at 7:37
• b3d.interplanety.org/en/… - for rotating without bpy.ops. Make sure you use appropriate axes and coordinates for defining distances and degrees. If you have any problems on writing the script - feel free to reply and ask, and I will get into as sooner as I can Jun 14, 2022 at 7:41