• Advertisement
Sign in to follow this  

arbitrary-axis rotation matrix

This topic is 4348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Not sure if this is the right place to post this, but i am trying to build a 4X4 matrix that will rotate a 3D object around an arbitraty axis (x,y,z) The axis vector (x,y,z) need not be normalized. The angle a is measured in radians. If the rotation axis faces the user, the rotation will be counterclockwise. x --> Specifies the X component of the axis of rotation. y --> Specifies the Y component of the axis of rotation. z --> Specifies the Z component of the axis of rotation. a --> Specifies the rotation angle, in radians. I am working in C++ and i think i am close, but while the object rotates it changes shape. Any help would be great, thanks.

Share this post


Link to post
Share on other sites
Advertisement
This can be found various places online [Edit: e.g. Sneftel's link], but here's another reference you can check your code against:
    // Some values you'll need (note that x, y and z are
// the components of the unit-length input axis):

T s = sin(angle);
T c = cos(angle);
T omc = (T)1.0 - c;

T xomc = x * omc;
T yomc = y * omc;
T zomc = z * omc;

T xxomc = x * xomc;
T xyomc = x * yomc;
T xzomc = x * zomc;
T yyomc = y * yomc;
T yzomc = y * zomc;
T zzomc = z * zomc;

T xs = x * s;
T ys = y * s;
T zs = z * s;

// The matrix is then:

[ xxomc + c, xyomc + zs, xzomc - ys ]
[ xyomc - zs, yyomc + c, yzomc + xs ]
[ xzomc + ys, yzomc - xs, zzomc + c ]

// This is in row-vector form; simply transpose if you're using column vectors.

Share this post


Link to post
Share on other sites
I got great help with my last question, and i have one last problem:

The alignment matrix aligns the model space Y axis with the specified
axis vector (x,y,z) (which need not be normalized). The rotation is
performed about the vector (a ^ b), where a is (0,1,0) and b is (x,y,z).

x --> Specifies the X component of the axis of alignment.
y --> Specifies the Y component of the axis of alignment.
z --> Specifies the Z component of the axis of alignment.

I am having some trouble building the 4X4 rotation matrix that preforms this action, any help would be great, Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement