sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Move vertex using absolute coordinate

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 1.7k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      metaclay
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        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
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @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 using transform_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">(&nbsp;</span><span class="syntaxdefault">new_position&nbsp;</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.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement