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

    Getting angle relative to component

    Scheduled Pinned Locked Moved Developers' Forum
    1 Posts 1 Posters 234 Views 1 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.
    • F Offline
      Frankn
      last edited by

      I'm using the following code to get the angle relative to the world axis and it works great but I'd also like to get the angle relative to the component which is selected when the cursor is inline with the component... like in the attachement where the angle read is 45 returned is 45 degrees I'd like it to be 0.0 degrees.

      
       @rotation_point=Geom;;Point3d.new(@iptemp.position)		    
       ptx=Geom;;Point3d.new(@ip2.position)
       ptx=Geom;;Point3d.new([ptx.x, ptx.y, @rotation_point.z]) 
       vector=@rotation_point.vector_to(ptx) 				
       crossvector=vector.cross(X_AXIS)
       multiplier=crossvector[2]
      		    
       if multiplier<0
         multiplier=1
       else
         multiplier=-1
       end 
      		    
       @angle=((X_AXIS.angle_between(vector)).radians)*multiplier
      
      

      I tried getting the component's angle and subtracting it from @angle but the results aren't very accurate for some reason. I also tried creating a new vector3d from the compoent instance's transformation and that gives me the same results

      			
       trans=parent_instance.transformation.to_a
       vector=Geom;;Vector3d.new(trans[0], trans[4], trans[8])
      
      

      angle ex.jpg

      Any ideas?

      EDIT: Found a solution
      Actually had the solution all along but it was so simple I overlooked it...
      subtracting the existing components angle from @angle does work... IF you do it in the right order!! 😳

      wrong...

       existing_comp_angle-@angle 
      

      right...

       @angle-existing_comp_angle 
      
      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