|
![](/i/fill.gif) |
Hi All,
I want to rotate an object. I couls use the rotate command but this function
is defined by the use of angles. Instead, I want to use units vectors that
describe the orientation.
knowing the orientation vector of my object (for example i = <1,0,0>), I
want to rotate this object such that the new orientation is, let's say, u =
<0,1,0>.
The code below creates a cylinder, coloured half blue and half red.
then I use a macro to rotate it. for that, I calculate the three Euler
angles and then use the command matrix to perform the three rotations for
each dimension x, y and z.
Problem : it doesn't work properly. For example, the transformation:
<1,0,0>) --> <0,1,0> doesn't work at all, but
<1,0,0>) --> <0,0,1> does !!
I Don't understand what is wrong ? (the angles calculation ?, the rotation
matrixes ? me ?). Can someone crack this ? Or has someone has a better
solution ?
Cheers
David
#declare MyObject = union{
cylinder{<0,0,0>,<3,0,0>,0.5 open texture { pigment { color 0,0,1>
}}}
cylinder{<3,0,0>,<6,0,0>,0.5 open texture { pigment { color<1,0,0>
}}}
}
object{
MyObject
align(<1,0,0>,<0,1,0>)
}
//=================================================
#macro align(i_vector,u_vector)
#local i_x = vdot( x, i_vector );
#local i_y = vdot( y, i_vector );
#local i_z = vdot( z, i_vector );
#local u_x = vdot( x, u_vector );
#local u_y = vdot( y, u_vector );
#local u_z = vdot( z, u_vector );
#local angl_z =
acos((u_x*i_x+u_y*i_y)/(sqrt(u_x*u_x+u_y*u_y)*sqrt(i_x*i_x+i_y*i_y)));
#local angl_y =
acos((u_x*i_x+u_z*i_z)/(sqrt(u_x*u_x+u_z*u_z)*sqrt(i_x*i_x+i_z*i_z)));
#local angl_x =
acos((u_y*i_y+u_z*i_z)/(sqrt(u_y*u_y+u_z*u_z)*sqrt(i_y*i_y+i_z*i_z)));
matrix< 1,0,0,
0,cos(angl_x),sin(angl_x),
0,-sin(angl_x),cos(angl_x),
0,0,0 >
matrix< cos(angl_y),0,-sin(angl_y),
0,1,0,
sin(angl_y),0,cos(angl_y),
0,0,0 >
matrix< cos(angl_z),sin(angl_z),0,
-sin(angl_z),cos(angl_z),0,
0,0,1,
0,0,0 >
#end
Post a reply to this message
|
![](/i/fill.gif) |