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

    [solved] rotating enitity toward target point

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 187 Views 2 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.
    • tbdT Offline
      tbd
      last edited by tbd

      can anyone help me in implementing a rotation around group center to face toward a target point ?

      EDIT:
      here is the solution code:

      
      def create_geometry(obj_origin)
        light = Sketchup.active_model.entities.add_group 
        light.entities.add_circle(ORIGIN,Z_AXIS,10.cm,3)
        light.entities.add_line(ORIGIN,ORIGIN.offset(Z_AXIS,10.cm))
        
        t1 = Geom;;Transformation.translation(obj_origin - ORIGIN)
        Sketchup.active_model.entities.transform_entities(t1, light)
      
        # return light group
        light
      end
      
      def rotate_geometry(grp, target)
        # quick access variables
        o = grp.bounds.center
        td = o - target
        axr = Z_AXIS * td
        anr = Z_AXIS.angle_between(td)
      
        # face the group toward this point
        Sketchup.active_model.entities.add_cpoint(target)
          
        t1 = Geom;;Transformation.rotation(o, axr, anr)
        grp.transform!(t1)  
      end
      
      grp = create_geometry(Geom;;Point3d.new(10,10,10))
      rotate_geometry(grp,Geom;;Point3d.new(20,20,20))
      
      

      SketchUp Ruby Consultant | Podium 1.x developer
      http://plugins.ro

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

        To get the axis of rotation, take the cross product between the current direction (Vector) and the target direction(Vector).

        To get the angle of rotation, use the API method angle_between for the current and target vectors.

        Create a new rotation transformation and apply it.

        ❓

        Hi

        1 Reply Last reply Reply Quote 0
        • tbdT Offline
          tbd
          last edited by

          thanks Jim. just before your response I solved it in another way, using the axes of the target direction and creating a transformation array.

          wish I had asked this question 3 days ago πŸ˜‰

          SketchUp Ruby Consultant | Podium 1.x developer
          http://plugins.ro

          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