sketchucation logo sketchucation
    • Login
    ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

    Transformation Troubles

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 303 Views
    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.
    • K Offline
      kdasilva
      last edited by kdasilva

      Hello again my new favourite forum~

      I come seeking guidance on working with transformations...

      I have a component, that gets placed upon the first click, a view line is then drawn which the user then uses to infer what angle, and what x scale to apply to the component (a big arrow in this case)

      so far:
      first click (gets placed)
      first click

      drawing the line
      drawing line

      second click (where my transformation skills fail me)
      second click

      As those show, my scale vector scales to the right size but my rotation just flips it onto its side. I tested each one independently, and they both moved the arrow back to the origin

      Here is the method I used for the transformation:

      
      def onLButtonDown flags, x, y, view
       if @first_click
         if (@pt1.position.distance @pt2.position) > 0
          draw_the_line
          rotate_vector = Geom;;Vector3d.new 0,0,1
          point_vector = @pt2.position - @pt1.position
          rotate_angle = rotate_vector.angle_between point_vector
          rotate = Geom;;Transformation.rotation( @pt1.position, rotate_vector, rotate_angle )
          xscale = @@edge.length.to_f / 72.25
          xscale_transformation = Geom;;Transformation.scaling @pt1.position, xscale, 1, 1
          @insert_arrow1.move!(Geom;;Transformation.new(xscale_transformation))
          @insert_arrow1.transform!(Geom;;Transformation.new(rotate))
         end
       else
        @pt1.pick view, x, y
        newpt = Geom;;Transformation.new( @pt1.position )
        @insert_arrow1 = @@ents.add_instance( @@comp_def_viewArrow, newpt)
        @first_click = true
       end
      end
      
      

      The reason i used .move! and then .transform! is because if I used both as .move! it seemed the second transformation cancelled out the first one (it wouldn't be scaled) and if I used .transform! for the scale it started jumping away (like the problem recently resolved in my previous tool post)

      Essentially my two issues are: Not having the transformation jump back to the origin, and the rotation I cant seem to work it always just flips up onto its side.

      My knowledge of vectors is pretty poor, so that very well might be the source of my issue.

      Cheers,

      Korbin~

      1 Reply Last reply Reply Quote 0
      • K Offline
        kdasilva
        last edited by

        oops I found a big mistake, that improved and made things worse...I realized I WAS clearing @pt1 and @pt2 with a reset call that was happening. So it was working all with zeros......however now that i removed that my arrows are going off in strange directions and rotating in ways i don't understand! I cuold really use some help from a transformation guru~


        After some testing I have a major question for my own understanding. How do multiple transformations work?? My scale will scale if its by itself, but as soon as I do two transformation (iescale with a rotation) the it starts to move somewhere else. From what I read I am guessing this has something to do with the transformation matrix ...but I can't seem to figure out how to navigate it.

        Is there a way to isolate each transformation? so they don't interact? (the !move worked for my last problem but not here..)

        cheers
        Korbin

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

          Transformations need to be done in a logical sequence if you use * they read right to left in sequence of application.
          If you manually locate, then rotate about a point and then scale an object you WILL get a different end result than if you locate, scale and then rotate it... It's the same with a coded transformation. Keep track of the points etc as you need to know clearly about which point you are rotating or scaling and that might move as you transform things [remember you can transform! a point too...]

          TIG

          1 Reply Last reply Reply Quote 0
          • K Offline
            kdasilva
            last edited by

            @tig said:

            Transformations need to be done in a logical sequence if you use * they read right to left in sequence of application.
            If you manually locate, then rotate about a point and then scale an object you WILL get a different end result than if you locate, scale and then rotate it... It's the same with a coded transformation. Keep track of the points etc as you need to know clearly about which point you are rotating or scaling and that might move as you transform things [remember you can transform! a point too...]

            hmm but my @pt 1, is the origin for rotation..and I scale form the point @pt1....so the point should never move....when I do them individually the component stays where it should...@pt1 doesnt change, I don't know what would make it want to translate to a a dif point. I do make sure to do the scale first, because that stretches in the X direction, so I do the scale before it gets rotated. So i see why order is important, but not why it translates my instance :S

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

              Get it to 'puts @pt1' into the Ruby Console with some text to show which 'state' case you are in - this will confirm if the points have inadvertently changed in your code...
              The first picked point [pt1] should locate the object.
              You know its start rotation against X_AXIS = 0.degrees, so its vector=X_AXIS.
              Next you move your cursor and a second point [pt2] is returned depending where it is.
              This sets a cursor_vector=pt1.vector_to(pt2) which you need to 'flatten' with cursor_vector.z=0.
              Every time pt2 changes you must set vector=cursor_vector.clone and then reset 'flattened' cursor_vector to suit the new point pt2 as before.
              Now you know the angle=vector.angle_between(cursor_vector) - you might need to test if the angle is +/-...
              Now as you move the cursor apply the rotation transformation to the object
              tr=Geom::Transformation.rotation(pt1, Z_AXIS, angle) object.transform!(tr)
              and then scale it along its x-axis to suit the new pt2
              [easiest if 'arrow' is made facing right - +ve x-axis - and its start length is 1" in x-axis too, as then there's less maths to do]
              scale=pt1.distance(pt2) tr=Geom::Transformation.scaling(pt1, scale, 1, 1) object.transform!(tr)
              [If you want to scale in other axes change the 1's for the y/z values]
              While waiting for the second point [pt2] this coding approach should then rotate the arrow towards the cursor and also stretch it towards the cursor - within the onMouseMove() method, the on click method will then 'freeze' these settings as 'pt2' is fixed...
              The steps I show ignore @ variables etc and are indicative only... BUT they should help resolve the issue... Fins a copy of my FreeRotate ruby that does something like this to rotate the object with the cursor about an initially picked point... all you need to add is something to 'flatten the rotation so you always rotate about the vertical Z axis and then the scaling parts... 🤓

              TIG

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @kdasilva said:

                From what I read I am guessing this has something to do with the transformation matrix ...but I can't seem to figure out how to navigate it.

                Martin Rinehart wrote a Tutorial that has a lesson on transformations and an explanation of the Matrix.

                See this post for links:
                http://forums.sketchucation.com/viewtopic.php?f=180&t=27182#p235251

                ( ...follow the white rabbit. )

                I'm not here much anymore.

                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