rotating a vector around another vector
i need to rotate a vector around another vector. i read something about rotating the coordinate system so that the z_axis is parallel to the vector which i want to rotate around. then rotating the vector (which i want to rotate) around the z_axis and then rotating the coordinate system back to its original direction. but it doesnt work, i think it is my math.
or is there an easier way of rotating a vector around another vector ?
I would build a matrix that represents the rotation around an axis with an angle and then multiply that matrix by the vector.
Build the matrix like this
c = cos(angle);
s = sin(angle);
Matrix.x.x = (Axis.x * Axis.x) * (1.0f - c) + c;
Matrix.x.y = (Axis.y * Axis.x) * (1.0f - c) + (Axis.z * s);
Matrix.x.z = (Axis.z * Axis.x) * (1.0f - c) - (Axis.y * s);
Matrix.x.w = 0.0f;
Matrix.y.x = (Axis.x * Axis.y) * (1.0f - c) - (Axis.z * s);
Matrix.y.y = (Axis.y * Axis.y) * (1.0f - c) + c;
Matrix.y.z = (Axis.z * Axis.y) * (1.0f - c) + (Axis.x * s);
Matrix.y.w = 0.0f;
Matrix.z.x = (Axis.x * Axis.z) * (1.0f - c) + (Axis.y * s);
Matrix.z.y = (Axis.y * Axis.z) * (1.0f - c) - (Axis.x * s);
Matrix.z.z = (Axis.z * Axis.z) * (1.0f - c) + c;
Matrix.z.w = 0.0f;
Matrix.t.x = 0.0f;
Matrix.t.y = 0.0f;
Matrix.t.z = 0.0f;
Matrix.t.w = 1.0f;
Angle must be in radians and the axis should be normalized.
Is this what you were looking for?
If the axis of rotation is parallell to the z-axis you dont need to use that rotation matrix you can just move the vector relative to the coordinate system and do the simpler (and faster) rotation about the z-axis:
Here is how you rotate a vector about the z-axis:
My post up, your post down, my site here
Edited by - Jesper T on February 12, 2002 3:00:01 PM
|
Here is how you rotate a vector about the z-axis:
|
Edited by - Jesper T on February 12, 2002 3:00:01 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement