The Angle between the plane and the X-axis

I want to know the Angle between a face and the X-axis, as shown in the figure below,I’m going to rotate the face 30 degrees counterclockwise, which is easier to calculate when it’s a rectangle, but what good way to calculate when a face is irregular.

I get a method from someone else, using the normal vector to calculate the Angle between a plane and the X-axis, Y-axis, and z-axis, but I don’t know how to get the θ,this is the code:

model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
face = selection[0]
vector_face_norm = face.normal
angle_to_x = vector_face_norm.angle_between X_AXIS
angle_to_x_deg = angle_to_x.radians
angle_to_y = vector_face_norm.angle_between Y_AXIS
angle_to_y_deg = angle_to_y.radians
angle_to_z = vector_face_norm.angle_between Z_AXIS
angle_to_z_deg = angle_to_z.radians

puts "Face normal angle to X axis: #{angle_to_x} rad, #{angle_to_x_deg}°"
puts "Face normal angle to Y axis: #{angle_to_y} rad, #{angle_to_y_deg}°"
puts "Face normal angle to Z axis: #{angle_to_z} rad, #{angle_to_z_deg}°"

That is an edge that lies on the plane

Is the face in the xy-plane or is it standing?
Is the angle theta in the xy-plane?

Notice that angle_between gives only positive angles between 0 and π (0° and 180°) but does not distinguish between a face normal rotated forward or backward from the x-axis.

# Intersect the face's (infinite) plane with xy-plane by computing the cross product of both normals.
# This is the vector through the face in xy-plane.
horizontal = face.normal * Z_AXIS
# Compute the angle considering orientation with atan2 (atan does not consider orientation).
theta = Math.atan2(X_AXIS.y - horizontal.y, X_AXIS.x - horizontal.x)
# Which gives for me something around -30°
1 Like

The face is standing,and the angle theta is in the xy-plane