Getting angle relative to component
-
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])
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
Advertisement