How to convert vector's direction
by ShaoWei · in Technical Issues · 12/01/2007 (10:07 pm) · 5 replies
I got a vector, and then want it to change its direction. For example the vector is "1 1 0", I want to konw how to convert 30 degree counterclockwise of the vector in xy plane? What should the result vector is ?
About the author
#2
mathworld.wolfram.com/RotationMatrix.html
12/02/2007 (5:03 pm)
This is a much more useful reference:mathworld.wolfram.com/RotationMatrix.html
#3
12/02/2007 (11:07 pm)
Thank you Matthew Jessick! I see that. I thought that the engine has this function, I look through out the reference, but has no answer! Thank you very much, I think this is the best place I hava ever found to shoot problems.
#4
MatrixF RotateMat(EulerF(0,0,rotRadiansZ));
RotateMat.mulV(myVector);
12/05/2007 (3:20 pm)
The engine does have a built in function to create rotation matrices.MatrixF RotateMat(EulerF(0,0,rotRadiansZ));
RotateMat.mulV(myVector);
Torque 3D Owner Matthew Jessick
The matrices for rotation about the principle axes (X,Y or Z) are well known.
What I did here was just to write out this multiplication in script.
// rotate input vector about the +Z axis // usage: echo(rotateVectorAboutZ("1 1 0",30)); function rotateVectorAboutZ(%vec, %angleDeg) // angle (degrees) positive for counter clockwise rotation in X-Y plane about +Z { %angleRad = mDegToRad(%angleDeg); %sinAngle = mSin(%angleRad); %cosAngle = mCos(%angleRad); %vx = getWord(%vec,0); %vy = getWord(%vec,1); %vz = getWord(%vec,2); return (%vx * %cosAngle - %vy * %sinAngle) SPC (%vx * %sinAngle + %vy * %cosAngle) SPC %vz; }The matrices look like:
en.wikipedia.org/wiki/Rotation_matrix
(I'm not sure this is very useful article for a beginner to rotations, but it does have pictures. The Qz() matrix was used here for a rotation about Z.)