sketchucation logo sketchucation
    • Login
    ๐Ÿค‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Geom::Transformation.new( Vector3d )

    Scheduled Pinned Locked Moved Developers' Forum
    31 Posts 7 Posters 1.1k Views 7 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
      MartinRinehart
      last edited by

      The docs say that a new Trans built with a vector translates (moves) by the vector. Am I doing something stupid or is a vector the same as a point (moving origin to that point)?

      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

      1 Reply Last reply Reply Quote 0
      • R Offline
        remus
        last edited by

        that sounds right. Whats not working?

        http://remusrendering.wordpress.com/

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

          v=[0,0,0].vector_to([20,50,30]) t=Geom::Transformation.new( v ) Sketchup.active_model.selection[0].transform!(t)
          This worked fine.

          Are you getting errors?
          Are you sure your vector is valid?

          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

            Yes and No... ๐Ÿ˜‰

            If you know the point to go to and are only moving one thing then use
            tr=Geom::Transformation.new(point)
            with
            object.transform!(tr)
            But if you are moving lots of things separately and you want to move them by a given amount along a vector, you don't want to work out every new point they'll be moved to individually - just work out a base point p1 and a new point p2 for one of them to get a vector and apply that vector to the translation...
            vector=p1.vector_to(p2) tr=Geom::Transformation.translation(vector) objects.each{|e|e.transform!(tr)}
            OR perhaps use a selection or group stuff temporarily to make an en mass translation...
            They'll each move by the same amount along that vector - much easier than trying to work out their individual base points and new points along a vector to then try to use .new(..) on...

            There's also entities.transform_by_vectors([entities_array],[vectors_array])
            If for example the entities_array were to be vertices or points and you want to move each individually along its own vector then the vectors_array would be made by some looping/calculating process for each of them - however if you just want to move them up say 1 unit then make a vector [0,0,1] and add that to the second array as many times as there are entities in the first array - the advantage of this method is that all of the 'entities' [e.g. vertices] are transform translated in one go - unlike the ..each{|e|..} method which moves them one at a time... ๐Ÿค“

            TIG

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

              @tig said:

              objects.each{|e|e.transform!(tr)}

              entities.transform_entities(objects,tr) ๐Ÿ˜‰

              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

                @thomthom said:

                @tig said:

                objects.each{|e|e.transform!(tr)}

                entities.transform_entities(objects,tr) ๐Ÿ˜‰

                Forgot to add that one ๐Ÿ˜ฎ
                Again they all get done at once rather than in steps...

                TIG

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MartinRinehart
                  last edited by

                  @remus said:

                  that sounds right. Whats not working?

                  foo.move!( trans.new(point) ) moves to point. Good.

                  trans.new( vec ) creates the same transformation as when you use a point (identity matrix plus r,g and b in the last row), ergo foo.move!( trans.new(vec) ) does not translate by vec. It moves to the point. Doc promises that it will translate by vec.

                  Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by

                    move! also resets the rotation and scale of Groups/Instances โ— โ“

                    Hi

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

                      @martinrinehart said:

                      @remus said:

                      that sounds right. Whats not working?

                      foo.move!( trans.new(point) ) moves to point. Good.

                      trans.new( vec ) creates the same transformation as when you use a point (identity matrix plus r,g and b in the last row), ergo foo.move!( trans.new(vec) ) does not translate by vec. It moves to the point. Doc promises that it will translate by vec.

                      No trans.new( vec ) makes a point transformation - moves the object to the given point - that's what .new does - since a vector looks just like a point [0,0,1] it'll use that ?
                      trans.translation(vec) - translates - i.e. moves from where it is along the given vector...
                      The move! method is used to apply a transformation to a Group or ComponentInstance.
                      It is the same as the transform! method except that it does not record the move in an undo operation. It is useful for transparently moving things during an animation.
                      Note how .move! only works with Groups and ComponentInstances but transform! can also be applied to Images, Point3d's, PolyMeshes and Vector3d's etc [but to transform Vertices you must use an entities.transform_entities(tr,[ents]) or entities.transform_by_vectors([ents],[vecs])]. For other things like Text and Cpoints you can only reset their insertion 'point' - which is a limited sort of transformation
                      The transformation must be of the type needed to produce the effect desire...
                      .new(point)
                      .translation(vector)
                      .rotation(various arguments)
                      .scaling(various arguments)
                      Thus you can transform many entities in a variety of ways...
                      Your .new(vec) simply confused SUp and since it wanted a point that's what it took the vector to be, as in fact they are pretty much interchangeable in the [x,y,z] format...
                      ๐Ÿ˜•

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        cjthompson
                        last edited by

                        I think the problem is that Transformation.new(Point3d) is the same transformation as Transformation.new(Vector3d), not the other way around. (if that makes any sense)

                        try this(assuming inst is a component instance):

                        
                        inst.transformation = Geom;;Transformation.new([10,0,0]) #places it at 10,0,0
                        inst.transform!(Geom;;Transformation.new(Geom;;Vector3d.new(20,20,0)))
                        inst.transformation.origin # => (30,20,0), like it should
                        
                        

                        then this:

                        
                        inst.transformation = Geom;;Transformation.new([10,0,0]) #places it at 10,0,0
                        inst.transform!(Geom;;Transformation.new(Geom;;Point3d.new(20,20,0)))
                        inst.transformation.origin # => (30,20,0), not (20,20,0)
                        
                        
                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          Yes, I see what you mean ...
                          inst.transformation = Geom::Transformation.new([10,0,0])
                          moves it to 10,0,0
                          inst.transform!(Geom::Transformation.new(Geom::Point3d.new(10,0,0)))
                          moves it by [10,0,0] from its current location - if that's [10,0,0] it moves to [20,0,0] as if had been passed a vector and NOT a point ??? ๐Ÿ˜• the same as .translation does...

                          So to 'transform!' inst to a fixed point you need
                          new_point=Geom::Point3d.new(1,0,0) inst.transformation = Geom::Transformation.new(new_point)

                          BUT 'move!' won't work as it takes a transformation as its argument and making a .new(point) transformation is no different from a .new(vector) transformation ? ๐Ÿ˜• ๐Ÿ˜•

                          In fact .new() can be several types of transformation not just 'point' as I said:

                          Geom::Transformation.new with no arguments creates a new identify Transformation.

                          Geom::Transformation.new(pt) creates a Transformation that translates the origin to pt. [This seems to be faulty as it's the transformation origin NOT the ORIGIN ??? i.e. NOT an ' Absolute' move but a ' Relative' one - Making it equivalent to using (vec) !!!]

                          Geom::Transformation.new(vec) creates a Transformation that translates by vector vec.

                          Geom::Transformation.new(transform) creates a Transformation that is a copy of another Transformation. This is equivalent to transform.clone.

                          Geom::Transformation.new(array) creates a Transformation from a 16 element Array.

                          Geom::Transformation.new(scale) creates a Transformation that does uniform scaling.
                          Geom::Transformation.new(origin, zaxis) creates a Transformation where origin is the new origin, and zaxis is the z axis. The x and y axes are determined using an arbitrary axis rule.

                          Geom::Transformation.new(pt, xaxis, yaxis) creates a Transformation given a new origin, x axis and y axis.

                          Geom::Transformation.new(pt, axis, angle) creates a Transformation that rotates by angle (given in radians) about a line defined by pt and axis.

                          [ruby:18i055ij]Geom::Transformation.new(xaxis, yaxis, zaxis, origin)[/ruby:18i055ij] creates a Transformation from 3 axes and an origin.

                          Confused, you will be... ๐Ÿ˜•

                          TIG

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

                            .move! is good when you want to move without affecting the undo-stack.

                            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

                              @thomthom said:

                              .move! is good when you want to move without affecting the undo-stack.

                              BUT since move! takes a transformation made in the form .new(pt) and that is no different from .new(vec) you can't move to an absolute point only a point relative to the transformation origin UNLESS you do some work beforehand to work out a .new(point) that's equivalent to an 'absolute' move ? ๐Ÿ˜•
                              You need to find the origin relative to the ORIGIN ? and go from there ? ๐Ÿ˜’

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                cjthompson
                                last edited by

                                @tig said:

                                @thomthom said:

                                .move! is good when you want to move without affecting the undo-stack.

                                BUT since move! takes a transformation made in the form .new(pt) and that is no different from .new(vec) you can't move to an absolute point only a point relative to the transformation origin UNLESS you do some work beforehand to work out a .new(point) that's equivalent to an 'absolute' move ? ๐Ÿ˜•
                                You need to find the origin relative to the ORIGIN ? and go from there ? ๐Ÿ˜’

                                Except that .move! is essentially the same as .transformation= (as far as I understand), so all you have to do is provide an absolute point.

                                EDIT: that might also be the source of Martin's confusion.

                                1 Reply Last reply Reply Quote 0
                                • M Offline
                                  MartinRinehart
                                  last edited by

                                  @tig said:

                                  Your .new(vec) simply confused SUp and since it wanted a point that's what it took the vector to be, as in fact they are pretty much interchangeable in the [x,y,z] format...

                                  "Geom::Transformation.new(pt) creates a Transformation that translates the origin to pt.

                                  Geom::Transformation.new(vec) creates a Transformation that translates by vector vec."

                                  (From http://code.google.com/apis/sketchup/docs/ourdoc/transformation.html#new )

                                  I do not get how translation() helps. Looks to me like it is identical to .new(pt) and .new(vec).

                                  Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                  1 Reply Last reply Reply Quote 0
                                  • M Offline
                                    MartinRinehart
                                    last edited by

                                    @tig said:

                                    you can't move to an absolute point only a point relative to the transformation origin

                                    Something really strange is happening here. When I move!() it is always to an absolute point, never to a relative point.

                                    Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      Jim
                                      last edited by

                                      @cjthompson said:

                                      Except that .move! is essentially the same as .transformation= (as far as I understand), so all you have to do is provide an absolute point.

                                      EDIT: that might also be the source of Martin's confusion.

                                      That would explain a lot, good observation.

                                      Hi

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

                                        I think the confusion is that .new(pt) reads like it should move 'absolutely' [from origin to point]
                                        whereas .new(vec) clearly moves by a vector from where it is by that vector...

                                        However it's now clear that .new(pt) moves to a point from the 'origin' where the 'origin' in the transformation origin, and not the model's ORIGIN [0,0,0] - i.e. it's relative just like .new(vec) - so there is no practical difference...

                                        To make an 'absolute' move in model-coordinates you need to work out the transformation origin relative to the ORIGIN...

                                        It's probably easier to simply do it in two steps - transform the instance/group so it's origin is then the ORIGIN, and then apply a move! on a .new(pt) transformation that will indeed be absolute...

                                        Here's a go...

                                        vec = inst.transformation.origin.vector_to(ORIGIN)
                                        tr = Geom;;Transformation.new(vec)
                                        inst.move!(tr)
                                        pt =  Geom;;Point3d.new(1,1,1)
                                        ### or any model coordinate point to 'move' to...
                                        tr = Geom;;Transformation.new(pt)
                                        inst.move!(tr)
                                        ### inst is NOW moved [transform! without undo] from wherever it was to the model point pt absolutely.
                                        ### the move is NOT immediately see as a view.invalidate is needed
                                        ### if transform! is used then you see the move straight off.
                                        

                                        It's 2 step but you could cunningly combine the two vectors to do it in one but why hurt your brain trying ? ๐Ÿค“

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • M Offline
                                          MartinRinehart
                                          last edited by

                                          @tig said:

                                          I think the confusion is that .new(pt) reads like it should move 'absolutely' [from origin to point]
                                          whereas .new(vec) clearly moves by a vector from where it is by that vector...

                                          Not at all. The confusion is that my result is the exact opposite of yours. Here's a set of things from my Ruby Console. sel() returns the currently selected ComponentInstance. where() returns elements 12, 13 and 14 of the instance's transformation().to_a(). GT, P3d and V3d are typing convenience classes that extend, unchanged, Geom::Transformation, Geom::Point3d and Geom::Vector3d, respectively.

                                          rc.jpg

                                          Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

                                            Confusion piled on confusion...
                                            I thought I had a good handle on transformations until today... ๐Ÿ˜ณ
                                            If I'm wrong, sorry... ๐Ÿ˜ž

                                            In any case I step back for a while until this gets sorted definitively... good luck... ๐Ÿ˜‰

                                            TIG

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

                                            Advertisement