# arbitrary-axis rotation matrix

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

## 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 on other sites
Well, check out how glRotate does it.

##### Share on other sites
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 on other sites
Thank you both, I had tried that matrix before but it looks like i was forgetting to normalize the vector, now its works like a charm :).

##### 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.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009836
• ### Who's Online (See full list)

There are no registered users currently online

×