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.

**0**

# arbitrary-axis rotation matrix

Started by Ultraseamus, May 31 2006 12:33 PM

4 replies to this topic

Sponsor:

###
#3
Members - Reputation: **1961**

Posted 31 May 2006 - 01:04 PM

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.

###
#5
Members - Reputation: **122**

Posted 31 May 2006 - 06:17 PM

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.

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.