Hello,
I posted this message before, but did not receive an answer.  However, I was able to figure out this myself.  I'm posting my solution for others.
 
Task:
Determine the new location of a point within a Transform group after the Transform group is rotated.
example:  Several Cylinders are pickable - the program needs to know where the TOP of the cylinders are located at any time after the user has rotated them separately.  (The transformgroup's center is the center of the cylinder.  The TOP is (0,cylinder_length/2,0) away from the center.)
 
Solution:
You need to get information on how the group was rotated.  The transform group's rotation is stored in the upper 3x3 section of a Matrix4d located in the Transform3d.
If one creates an AxisAngle4d and uses .set(the_transfrom3d_Matrix4d), then the AxisAngle will have the x, y, z components of a vector and an angle stored in it.  This describes the rotation from the original position of the transform group.
 
For instance, if one was to rotate a cylinder 90 degrees clockwise, then they are essentially rotating -90 degrees about the vector (0,0,1) -the z-axis.  The negative appears because of the right hand rule dictating the angle is to be incremented in counter-clockwise rotation.
 
Another way to look at it is rotation +90 about the vector (0,0,-1).
 
This seems simple, but try picturing an oddball rotation.  The vector to describe the rotation would have to be such that the cylinder would be perpendicular to it throughout the rotation. So you could get some funky vectors back from you AxisAngle4d.
 
The hard part is making the vector mean something to you.  The way it is done is as follows:
 
 
The Smack-it-up-flip-it Method:
 
Rotate the vector counter-clockwise about the y-axis until the vector is in the y-z plane.  This requires some trigonometry to determine the angle between the original vector and the y-z plane.  The resulting equation is most easily written in the form of a matrix-so you'll need a Matrix4d to store the rotation information.  (write me if you want the matrices involved).  Note that you are using the VECTORs x, y, z in these rotations.  The coordinates of interest are not factored in until you're done smacking and flipping.
 
Next, rotate the vector around the x-axis counter-clockwise until the vector lies on the +z axis.  Once again, use some trig. to determine the angle between the original vector and the +z axis.
 
Now you can rotate around the z-axis using the AxisAngle's angle returned.
 
To finish up, you rotate back off the Z axis, and then rotate back to the original vector direction (basically, reverse the process).
 
After doing this, you should have a matrix for the y rotation, x rotation, z rotation, other y rotation, and other x rotation.  You now multiply the original coordinates (relative to the center of the Transform) by the product of all those matrices and you have the new coordinates position.  (To multiply a matrix, you use matrix1.mul(matrix2) ).
 
These coordinates are relative to the center of the object (cylinder), to figure out where they are in the scene, just add them to the objects center coordinates.  This is actually called a translation.
 
 
For a picture of what I just said, go to http://graphics.cs.ucdavis.edu/GraphicsNotes/Rotation/Rotation.html
 
If anyone knows of a method I missed that already performs this, let me know!!!
 
Thanks,
Sean
 
 
 
 
 
 

Reply via email to