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

Rotating objects in space

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 590 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.
  • H Offline
    honoluludesktop
    last edited by 6 Nov 2010, 02:33

    The following code rotates an object on its origin by pointing its zaxis towards a point on the model.

    sel_trans = sel_comp.transformation sel_origin = sel_trans.origin new_vector = sel_origin.vector_to point_here new_trans = Geom::Transformation.new(sel_origin, new_vector) sel_comp.transformation = new_trans

    Problem is that the new_tran('s) xaxis, and yaxis are arbitrary set by Geom::Transformation.new. If the object is not symmetrical, the rotation can be unexpected (pointing z is OK). Any suggestions?

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 6 Nov 2010, 03:49

      Well, its hard to define what the absolute "right" way is to rotate something in 3d.

      I'm guessing what you would like to see is 2 part process. First rotate on the x axis and apply the transformation, then rotate on the y axis. That might give you what seems to be a more logical result.

      How to do that is beyond me at the moment - you would have to figure out just how far to rotate on x so that when you rotate on the y the object is poting exactly to the desired target. Maybe its easier to do than I can think of right now. Hopefully your brain will think it through faster than mine.

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • H Offline
        honoluludesktop
        last edited by 6 Nov 2010, 08:55

        Sigh.....I was hoping it was just a method I missed. Thanks, guess I'll get back to this one later.

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 6 Nov 2010, 10:37

          Use a .cross method on the zaxis and new_vector to get a vector perpendicular to them - you can then use that as a normal for a rotation transformation using the angle between the zaxis and the new_vector...

          What exactly are you trying to do ??

          TIG

          1 Reply Last reply Reply Quote 0
          • H Offline
            honoluludesktop
            last edited by 6 Nov 2010, 11:25

            Hi Tig, The first Ruby I ever wrote (some time last year) was recently posted here. I did so before realizing that you did "Free Rotate". Still, I would like to learn, and fix my code. I watched the demo video, and didn't open yours assuming that it was to sophisticated for me to understand, and just posted my question here. 😳

            1 Reply Last reply Reply Quote 0
            • C Offline
              Cleverbeans
              last edited by 8 Nov 2010, 19:36

              When dealing with rotations in 3D I think it's a common misconception to consider the "direct" rotation as the only rotation since in 2D there is only ever one rotation to move a vector to point towards another. Say for example you wanted to rotate the vector (1,0,0) to the vector (0,1,0). I think most people would envision the rotation as holding the z-axis fixed the path traced by the vector as being a quarter circle in the x-y plane. However there are infinitely many rotations that will take one vector to the other!

              For a simple one, consider looking down at the origin from the point (0.5,0.5,0). From here, you can rotate 180 degrees around the (0.5,0.5,0) vector and it will achieve the same result of moving (1,0,0) to (0,1,0). Another somewhat harder rotation to see is rotating by 120 degrees around the vector (1,1,1) which is equivalent to moving each axis to another axis. In each of these cases the z-axis behaves differently under the rotation so this is where the complication in your original code stems from.

              If the behavior your looking for is the direct rotation than the suggestion given by TIG is the correct one, and should provide the expected behavior.

              1 Reply Last reply Reply Quote 0
              • H Offline
                honoluludesktop
                last edited by 11 Dec 2010, 12:10

                Well, better late then never. Not as difficult as I thought. First point, then rotate:

                ` comp.transformation=Geom::Transformation.new(comp.transformation.origin,point_vector)

                comp.transform! Geom::Transformation.new(comp.transformation.origin,comp.transformation.zaxis, (Math::PI*3)/2)`

                Thanks everyone.

                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