How to rotate a group or a component according to a face normal?

Hello,

I have a group glued to ground and a face inclined to a certain degree. I’m looking into rotate group according to face normal (vector) so bottom face of group become perpendicular to inclined face but I’m missing angle parameter or something other… Can you please help me? Thank you!

Screenshot

Draft code

point = group.bounds.center
vector = face.normal
angle = 0 # unknown!

transformation = Geom::Transformation.rotation(point, vector, angle)

group.transform!(transformation)

Transformation.rotation is only useful when you know an exact rotation line. For this I’d use Transformation.new(point, normal).

1 Like

Thank for your help @eneroth3 but unfortunately this doesn’t solve problem. After transformation group seems well inclined but it is moved to a location different of point. How can I correct this? I tried group.transform!(Geom::Transformation.translation(group_point)) with no luck…

Screenshot

Draft code

group_point = group.bounds.center

face_vector = face.normal

group.transform!(
    Geom::Transformation.new(group_point, face_vector)
)

After the first Transformation do a second Transformation, this time to .position the group at the group_point…

Thanks @TIG. Finally, I found a solution: Move group to origin before apply vector transformation.

Screenshot

Final code

group_point = group.bounds.center

face_vector = face.normal

group.move!(Geom::Transformation.translation(ORIGIN))

group.transform!(
    Geom::Transformation.new(group_point, face_vector)
)

There are some oddities in the API here that could be worth explaining.

transform! honors an objects original position (also a transformation) and moves it from there.

transform= sets the transformation of the object, totally overriding what transformation it already had.

The name move!suggest a relationship to transform! but it is actually much more like transformation= that it just sets a transformation, overriding what was already there. Its difference from transformation= is that it isn’t added to the undo stack, which is useful for animations.

group.move!(Geom::Transformation.translation(ORIGIN)) is geometrically identical to group.transformation = IDENITY as Transformation.translation(ORIGIN) returns an identity transformation. It represents either no movement or the object being aligned with the parent axes, depending on how you apply it.

Since transformation= ignores any existing value when writing the transformation, you could use it only once and skip the previous step of “resetting” the position.

group.transformation = Geom::Transformation.new(group_point, face_vector)
3 Likes