[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_between
for 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
Advertisement