sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Transformation.rotation help

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 925 Views 4 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.
    • s_k_e_t_c_h_yS Offline
      s_k_e_t_c_h_y
      last edited by

      Hi,
      I can't get this to work quite right so I was hoping for some insight. The Transformation.rotation is a bit light on documentation in the API.

      @unknownuser said:

      Transformation.rotationSketchUp 6.0+
      The rotation method is used to create a Transformation that does rotation about an axis.

      The axis is defined by a point and a vector. The angle is given in radians.

      Arguments:

      point
      A Point3d object.
      vector
      A Vector3d object.
      angle
      A numeric value, expressed in radians, that specifies the angle to rotate about the axis set by the second parameter.
      Returns:

      transformation
      a new Transformation object

      From what I understand the point will be in 3D, but the Vector has to only contain 1 Dimension (i.e. the axis you'll be rotating around such as [0,0,1] or [1,0,0]).

      What I want to do is rotate to a vector in 3D, which is essentially 2 successive rotations around axes such as y then x. The problem is that the two rotations that equal my 3d vector's direction don't lead to a correct rotation, but if I do only one of the rotations each seems correct for its respective axis.

      I have a feeling I may need to just enter my own transformation matrix, but I was hoping I could just do it with existing commands...thoughts?

      To make it a bit clearer here is an image. I want to rotate and translate an object from a point (origin in this case) to the end of a vector. This requires a rotation in two planes and a translation...
      rotation.png

      You can do the rotations with one operation in SU so I'm presuming I'm just missing something...

      Sketchy..

      1 Reply Last reply Reply Quote 0
      • s_k_e_t_c_h_yS Offline
        s_k_e_t_c_h_y
        last edited by

        You can see how it is wrong....

        blah.png

        Here is the code....

        
        						p = Geom;;Point3d.new([0, 0, 0])    #Point of rotation	
        						
        						#Create a copy, but don't move it (it needs rotating first
        						trans = Geom;;Transformation.translation([0,0,0])
        						new_hub = @geodesic.entities.add_instance hub_def, trans
        						
        						#Create a vector pointing up the Z axis
        						z_vec = Geom;;Vector3d.new [0, 0, 1]
        						
        						#Turn our target point into a vector
        						cv = Geom;;Vector3d.new c[0], c[1], c[2]
        						
        						#Get the angle between the Z-axis and the vector
        						angle = z_vec.angle_between cv
        						
        						#Create a rotation transform and rotate the object
        						r1 = Geom;;Transformation.rotation(p, cv, angle)
        						new_hub.transform!(r1)
        						
        						#Translate to final destination
        						t = Geom;;Transformation.translation(c)
        						new_hub.transform!(t)
        
        1 Reply Last reply Reply Quote 0
        • renderizaR Offline
          renderiza
          last edited by

          Hi,

          The following example code aligns the object axis with line axis pretty close, its a little off but not by much...not sure why this happens.

          Here is the code;

          model = Sketchup.active_model
          ents = model.active_entities
          sel = model.selection
          
          @rotx = 0
          @roty = 0
          @rotz = 0
          
          #change to see diferent line rotations
          edge = Sketchup.active_model.entities.add_line([0,0,0],[-400,700,200])
          
          line = edge.line
          lend = edge.end
          lendp = lend.position
          
          sel.each do |e|
              pi = Math.acos(-1)
              @rotx = Math;;acos(line[1].x)*(180/pi) #/
              @roty = Math;;acos(line[1].y)*(180/pi) #/
              @rotz = Math;;acos(line[1].z)*(180/pi) #/   
          end
          
          tobject = sel[0]
          
          
          tr1 = Geom;;Transformation.rotation(ORIGIN, Y_AXIS, @rotz.degrees)
          tr2 = Geom;;Transformation.rotation(ORIGIN, Z_AXIS, @rotx.degrees)
          tr3 = Geom;;Transformation.new([lendp.x, lendp.y, lendp.z])
          
          instance = ents.add_instance(tobject.definition, tr1)
          instance = instance.transform!(tr2)
          instance = instance.transform!(tr3)
          

          Note: before running code you need to have a group selected.

          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

          1 Reply Last reply Reply Quote 0
          • fredo6F Offline
            fredo6
            last edited by

            @s_k_e_t_c_h_y said:

            To make it a bit clearer here is an image. I want to rotate and translate an object from a point (origin in this case) to the end of a vector. This requires a rotation in two planes and a translation...
            [attachment=0:3fw9rw9b]<!-- ia0 -->rotation.png<!-- ia0 -->[/attachment:3fw9rw9b]

            You can do the rotations with one operation in SU so I'm presuming I'm just missing something...

            Sketchy..

            I think you should try the Axis Transformation, which can do it in one go.
            You have the Z direction (your vector), and you need to fix the X or Y direction in the plane normal to your vector (or let SU decide by simply using an axes system based on vec.axes.

            Fredo

            1 Reply Last reply Reply Quote 0
            • tt_suT Offline
              tt_su
              last edited by

              What fredo said, Transformation.axes sounds like the method you want to use: http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation.php#axes

              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