[solved] rotating enitity toward target point
-
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)) -
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_betweenfor the current and target vectors.Create a new rotation transformation and apply it.

-
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

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement