Curious issues with relative/global vertex positions

I have found, like many others, that when a group is open, an edge/face’s vertex positions will show their position in global terms, whereas when a group is closed, that same edge/face will show the local position.

My question is, what if you’d like to apply a transformation inside the group along those local axes? If I have a set of vertices and then close the group and apply a translation, it occurs along the local axes, but what if I want to apply the translation with the group open?

e.g., if I have a parent_group and I want to do parent_group.entities.transform_entities(TRANSLATION, vertices) how can I correctly apply that without closing the group? I have tried to apply the inversion of the active model edit_transform and reapplying it afterward, but that did not work either.

You would probably have to multiply the edit_transform by the local transform and then apply that to the vertices.

REF:

If the use has drilled down multiple levels, you can use the active path array’s members to build a compound transformation.

REF:

This has been explained before quite well by @eneroth3 and @Aerilius here in this category.

Search:
https://forums.sketchup.com/search?q=@eneroth3%20transformation%20category:13

Hi Dan, I’ve tried multiple variations of multiplying the local transform by the edit_transform and none of them have produced the correct result. I have searched through several of those threads by eneroth and Aerilius already and not been able to come up with something.

Here’s an example of what I’d want to do

tr = Geom::Transformation.translation([1, 0, 0])
vertices = Sketchup.active_model.selection.map{|e| e.vertices}
ed_tr = Sketchup.active_model.edit_transform
parent_group = Sketchup.active_model.active_path.last
parent_group.entities.transform(ed_tr * tr, vertices)

I have tried applying this same transformation to Sketchup.active_model.entities but it also fails there. As long as the group is open for editing, this transformation does the incorrect thing. I see that I can get the correct local positions for a set of vertices by doing selection_vertices.map{|e| e.position.transform(Sketchup.active_model.edit_transform.inverse)} but how do I use that to my advantage in the transformation of the entities themselves?

Aha, I think I’ve got it – I should have paid more attention in linear :wink:

Thus, the order of the transformations really DOES matter, and quite a bit.

Sketchup.active_model.active_entities.transform_entities(pgt * tr1 * pgt.inverse, verts)

Where pgt is the parent_group's local_transformation. This seems to have the intended effect.

Edit to add:

tr1 is simply Geom::Transformation.translation(Geom::Vector3d.new(5, 0, 0)) or something else equally trivial.

2 Likes

It’s always best when you figure it out yourself.

It’s like a little reward. I appreciate the pointer to active_path, though. I was getting the parent object in a more convoluted way, and this will make it easier to construct my tool.

1 Like