## move vertex using absolute coordinate

### move vertex using absolute coordinate

Hi, i'm new to ruby. I'd like to know how to move vertex using absolute coordinate ? i used transform_by_vectors and transform_entities , they only provide relative transformation.

Thanx
metaclay

Posts: 14
Joined: Mon Jun 25, 2012 11:51 am
Name: andi

### Re: move vertex using absolute coordinate

Calculate the final destination based on the original position.

vector = vertex.position.vector_to( new_position )
entities.transform_by_vectors( [vertex], [vector] )
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17673
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
SketchUp use: architecture

### Re: move vertex using absolute coordinate

trt=Geom:Transformation.translation(vector)
then
obj.transform!(trt)
moves the object by length of the vector in the direction of the vector.
trn=Geom:Transformation.new(point)
then
obj.transform!(trn)
moves the object to the specified point irrespective of where is is beforehand.
To move an array of vertices you can use
entities.transform_entities(trt, vertices)
when they'll all shunt over in the direction of vector by the length of vector.
If you have a collection of different vectors for different vertices then use
entities.transform_by_vectors(vertices_array, vectors_array)

You don't want to to apply a 'move' trn type of transformation as they'd all end up coincident !

If you have an array of 'vertices' and a matching array of their new absolute 'positions'... then use an iteration...
vertices.each_with_index{|v, i|
pt=positions[i]
tr=Geom:Transformation.new(pt)
entities.transform_entities(tr, v)
}

Each vertex in turn is then assigned the new position [point]...
TIG

TIG
Global Moderator

Posts: 13998
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: move vertex using absolute coordinate

TIG wrote:If you have an array of 'vertices' and a matching array of their new absolute 'positions'... then use an iteration...
vertices.each_with_index{|v, i|
pt=positions[i]
tr=Geom:Transformation.new(pt)
entities.transform_entities(tr, v)
}

Each vertex in turn is then assigned the new position [point]...

Very inefficient! You want to transform all at once.
What I do for vertex tools is by using transform_by_vectors

Code: Select all
`vectors = []vertices.each_with_index{|vertex, i|  new_position = new_positions_array[i]  vectors << vertex.position.vector_to( new_position )}entities.transform_by_vectors( vertices, vectors ) `

At all times try to use bulk methods that updates multiple entities at the same time. Even for selections, don't use add/remove within an iterator - use a cache array and update in bulk afterwards. It's the difference between minutes and seconds.
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17673
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
SketchUp use: architecture

### Re: move vertex using absolute coordinate

That is a much more efficient way of doing it [transforming [or erasing] entities en mass is often preferable]... But in my defense... the title of the post is move vertex... NOT move vertices... - so there is probably no significant benefit in the en mass way when he's moving just one or two or three vertices - obviously if a whole load of things are changing a time lag will be noticeable...
TIG

TIG
Global Moderator

Posts: 13998
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

Need Authorised SketchUp Training by experts in various disciplines? Check out our Training details.