Transformation.rotation help
-
Hi,
I can't get this to work quite right so I was hoping for some insight. The Transformation.rotation is a bit light on documentation in the API.@unknownuser said:
Transformation.rotationSketchUp 6.0+
The rotation method is used to create a Transformation that does rotation about an axis.The axis is defined by a point and a vector. The angle is given in radians.
Arguments:
point
A Point3d object.
vector
A Vector3d object.
angle
A numeric value, expressed in radians, that specifies the angle to rotate about the axis set by the second parameter.
Returns:transformation
a new Transformation objectFrom what I understand the point will be in 3D, but the Vector has to only contain 1 Dimension (i.e. the axis you'll be rotating around such as [0,0,1] or [1,0,0]).
What I want to do is rotate to a vector in 3D, which is essentially 2 successive rotations around axes such as y then x. The problem is that the two rotations that equal my 3d vector's direction don't lead to a correct rotation, but if I do only one of the rotations each seems correct for its respective axis.
I have a feeling I may need to just enter my own transformation matrix, but I was hoping I could just do it with existing commands...thoughts?
To make it a bit clearer here is an image. I want to rotate and translate an object from a point (origin in this case) to the end of a vector. This requires a rotation in two planes and a translation...
You can do the rotations with one operation in SU so I'm presuming I'm just missing something...
Sketchy..
-
You can see how it is wrong....
Here is the code....
p = Geom;;Point3d.new([0, 0, 0]) #Point of rotation #Create a copy, but don't move it (it needs rotating first trans = Geom;;Transformation.translation([0,0,0]) new_hub = @geodesic.entities.add_instance hub_def, trans #Create a vector pointing up the Z axis z_vec = Geom;;Vector3d.new [0, 0, 1] #Turn our target point into a vector cv = Geom;;Vector3d.new c[0], c[1], c[2] #Get the angle between the Z-axis and the vector angle = z_vec.angle_between cv #Create a rotation transform and rotate the object r1 = Geom;;Transformation.rotation(p, cv, angle) new_hub.transform!(r1) #Translate to final destination t = Geom;;Transformation.translation(c) new_hub.transform!(t)
-
Hi,
The following example code aligns the object axis with line axis pretty close, its a little off but not by much...not sure why this happens.
Here is the code;
model = Sketchup.active_model ents = model.active_entities sel = model.selection @rotx = 0 @roty = 0 @rotz = 0 #change to see diferent line rotations edge = Sketchup.active_model.entities.add_line([0,0,0],[-400,700,200]) line = edge.line lend = edge.end lendp = lend.position sel.each do |e| pi = Math.acos(-1) @rotx = Math;;acos(line[1].x)*(180/pi) #/ @roty = Math;;acos(line[1].y)*(180/pi) #/ @rotz = Math;;acos(line[1].z)*(180/pi) #/ end tobject = sel[0] tr1 = Geom;;Transformation.rotation(ORIGIN, Y_AXIS, @rotz.degrees) tr2 = Geom;;Transformation.rotation(ORIGIN, Z_AXIS, @rotx.degrees) tr3 = Geom;;Transformation.new([lendp.x, lendp.y, lendp.z]) instance = ents.add_instance(tobject.definition, tr1) instance = instance.transform!(tr2) instance = instance.transform!(tr3)
Note: before running code you need to have a group selected.
-
@s_k_e_t_c_h_y said:
To make it a bit clearer here is an image. I want to rotate and translate an object from a point (origin in this case) to the end of a vector. This requires a rotation in two planes and a translation...
[attachment=0:3fw9rw9b]<!-- ia0 -->rotation.png<!-- ia0 -->[/attachment:3fw9rw9b]You can do the rotations with one operation in SU so I'm presuming I'm just missing something...
Sketchy..
I think you should try the Axis Transformation, which can do it in one go.
You have the Z direction (your vector), and you need to fix the X or Y direction in the plane normal to your vector (or let SU decide by simply using an axes system based onvec.axes
.Fredo
-
What fredo said, Transformation.axes sounds like the method you want to use: http://www.sketchup.com/intl/en/developer/docs/ourdoc/transformation.php#axes
Advertisement