1. - Take a look at the JavaDocs for the Trasform3D class. For your first question it will be something like this (simplified and abbreviated code):
// Create and/or reuse Transform3D objects:
xTrasform.rotX(xAngle);
yTranform.rotY(yAngle);
zTransform.rotZ(zAngle);
finalTransform.set(initialVector);
finalTrasform.mul(xTrasform);
finalTrasform.mul(yTrasform);
finalTrasform.mul(zTrasform);
finalTrasform.get(finalVector);
2. - The answer to this question is a little more problematic.
What constitutes an object perpendicular to a Vector. In reality
it is a plane, not another vector. If you want a vector which is
90 degrees to an up vector (for example) it could be either to the left
, right, towards you, away from you or anywhere in between. There
is a method, the cross product, which will find a vector perpendicular
to two other vectors (see the Vector3d class method cross(Vector3d, Vector3d).
- A common occurence of the problem is when you
tilt your camera or object and you want to know where is the left, right,
up and down with respect to new orientation. The way to do this is
a sequence of cross products and re-cross products like this:
newLeftVector.cross(oldUpVector,
newOrientationVector);
newUpVector.cross(newOrientationVector,
newLeftVector);
(Note that the order of the vectors in the argument is significant.
Imagine all the extended fingers of your RIGHT hand initially pointing
in the of oldUpVector and slowly curling so the tips point to newOrientationVector.
The extended thumb now points to newLeftVector. Reversing the order
of the arguments means the method would create newRightVector instead.)
If you don't have an up vector or something
similar, and you don't care where the perpendicular points, you create
a arbitrary new vector and cross it with the original. As long as
the new vector you create isn't parallel with the original you're OK (easiest
way to do that is to take the original and change only one of the three
component values to create the new vector).
In most of these cases you do not need magnitude
so it is usually a good idea to normalize the vectors when done (myVector.normalize();).
Hope this helps - Gary
gaoming fu wrote:
Hi, All I have two questions about Vector3d. 1. If I have a Vector3d, e.g., (1.0, 0.1, 0.1), and I want to rotate it with 45 degrees about x-axis, 135 degrees about y-axis, then 300 degrees about z-axis. After these rotations, how to find the new Vector? 2. How to find a Vector which is perpendicular to another Vector, e.g., (1.0, 0.1, 0.1) ? Thanks a lot. Gaoming Fu
Get your FREE download of MSN Explorer at http://explorer.msn.com
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
