The azimuth and tilt of surface


As shown in the figure above, for an arbitrary surface, how can I calculate the azimuth and tilt of this surface through ruby language?

If this is a face, then it will be a Sketchup::Face object, and it has a normal vector.
The face you post looks to be on the ground plane, and SketchUp treats these special and positions them front side facing downward (in preparation for a push-pull upward,) so the normal vector would also point downward (unless you reverse the face.)

The face also has vertices which have a position in 3D model space (which have x, y, z coordinates.)


If the geometry you show has been grouped, then the group has a transformation describing it’s translational origin (relative to the global model ORIGIN,) and any rotation and scaling.

1 Like

I mean, can I get the azimuth and tilt of this face by some ruby language compilation method, just like skelion

Azimuth from what point? A face’s normal vector tells you the “tilt”.

I know nothing of Skelion, nor does it matter.

What’s your point of reference for the azumuth and tilt? Ground plane and the X_axis? And what is the local orientation reference of your face?

Quick and dirty:

  • Open the Ruby console (Window menu >> Ruby Console)
  • Select the face in question (only the face)
  • Copy the code below and paste it to Ruby Console
  • Hit Enter key
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}°"

You will get 3 angles (in radians and in degrees) in the last 3 lines of Ruby Console. You can decide which one is the azimuth and tilt… :wink:
Note: this will work if the face not in a group or component… otherwise you will have to follow advise from @DanRathbun. (If you hadn’t noticed, there is a lot of useful information in the links he posted.)