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
-
Calculate the final destination based on the original position.
vector = vertex.position.vector_to( new_position ) entities.transform_by_vectors( [vertex], [vector] ) -
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'
trntype 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 said:
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 usingtransform_by_vectors<span class="syntaxdefault"><br />vectors </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[]<br /></span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each_with_index</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">vertex</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> i</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault">  new_position </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> new_positions_array</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">  vectors </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> vertex</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vector_to</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">new_position </span><span class="syntaxkeyword">)<br />}<br /></span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform_by_vectors</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> vertices</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> vectors </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span>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.
-
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**...NOTmove **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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement