Jump to content

  • Log In with Google      Sign In   
  • Create Account


arbitrary-axis rotation matrix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Ultraseamus   Members   -  Reputation: 122

Like
0Likes
Like

Posted 31 May 2006 - 12:33 PM

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.

Sponsor:

#2 Sneftel   Senior Moderators   -  Reputation: 1773

Like
0Likes
Like

Posted 31 May 2006 - 12:59 PM

Well, check out how glRotate does it.

#3 scgames   Members   -  Reputation: 1961

Like
0Likes
Like

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.


#4 Ultraseamus   Members   -  Reputation: 122

Like
0Likes
Like

Posted 31 May 2006 - 01:42 PM

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 :).

#5 Ultraseamus   Members   -  Reputation: 122

Like
0Likes
Like

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS