.transform! doesn't keep the transformation

Hello
I want to change some points of my edges.
It seems to work , but when the functiion ends, the points have the former coordinates.
I use transform! which is supposed to modify the point, as I understand.
Where is my mistake ?

 UI.messagebox to_change.length
to_change.each do |edge|
vertex = edge.end
point = vertex.position
puts "before #{point.x} , #{point.y} , #{point.z}"
vector = point.vector_to [point.x,point.y,0]
tr = Geom::Transformation.translation vector
point.transform! tr
puts "after #{point.x} , #{point.y} , #{point.z}"
end

before 171,8422mm , 290,5582mm , 0,1044mm
after 171,8422mm , 290,5582mm , 0,0000mm
before -55,5479mm , 607,8201mm , 0,1043mm
after -55,5479mm , 607,8201mm , 0,0000mm

You construct your vector to go from the point to its projection onto the x,y plane: it has values [0,0,-point.z]. Apply this as a transformation, and it leaves the x and y coordinates unchanged while moving the z value to 0.

You need to transform the vertices themselves. The points retrieved from their position are not associated with the edges.

1 Like

You are right! I may have focused too much on the code snippet and missed the actual goal!

Thanks slbaumgartner, jim_foltz
I’m not used to all these concepts, I will train;)
I take advantage of your help, to ask how to use the transformation to modify the two points of a vertex… The transformation for a vertice will make a translation, which is not what I want.

To move a single vertex. Assume the model consists of a single Edge.

model = Sketchup.active_model
entities = model.entities
edge = entities[0]
a = edge.start
b = edge.end
tr = Geom::Transformation.translation([0, 0, 1])
entities.transform_entities(tr, [b])

Use Entities#transform_entities(Transformation, array_of_entities) to transform a list of entities by the same Transformation.

Use Entities#transform_by_vectors(array_of_entities, array_of_vectors) to transform a list of entities each by a different vector. array_of_entities and array_of_vectors must be the same length.

1 Like