Sign in to follow this  
Code Mole

Rotating a Point around a given Axis

Recommended Posts

How does one rotate a point around a given axis? I Know the matrices for rotating around the X,Y,Z axis, but what if one want's to rotate around the XY axis? I tried doing some cleaver matrix math were I rotate the given axis to map it on the X-axis then rotate around X-axis and undone those other rotations to map the point back. I thought that would work but it doesn't seem to. example I'd form a matrix like so Ma = Mz-@ * My-Q * Mxp * MyQ* Mz@ where Mz - matrix for roatating around Z to get the xz plane My - matrix for rotating around Y to get on the X axis Mx - matrix for rotation around X My- - matrix undoes Y rotation Mz- - matrix undoes Z rotation p - radian to rotate the point around the given axis @ - the radian to rotate the axis from xy plane to the x-axis (I get Q by dotting the projection of the axis(I make it a vector) on the xy plane with the x-axis) Q - the radian to rotate to the xy plane (I get Q by dotting the projection of the axis(I make it a vector) on the xz plane with the x-axis shouldn't that work? or is there certain axis' that if one tries this method on, it would fail? Is there a better way to calculate a rotation matrix given a random vector(axis) to rotate around? thanks code mole

Share this post


Link to post
Share on other sites
I didn't work through your example, but there's a standard equation to rotate a vector v about a unit-length axis n:

v' = (v.n)n+cos(t)(v-(v.n)n)+sin(t)(nXv)

This equation can be used as-is, or expanded into matrix form:

v' = Mv

Or:

v' = vM

Where M is an axis-angle rotation matrix. (A google for 'axis angle matrix' should turn up the formulation.)

The standard X, Y and Z rotation matrices are just special cases of the above.

Share this post


Link to post
Share on other sites
This is what I do.
Thing quaternion are relative rotation around a fix axis, you could used the definitytion to build a relative rotation matrix.

Say the normalized axis is the quaternion axis, then the quaternion that will produce the rotation is:

Ruat rot (cos (angle * 0.5), sin(angle * 0.5) * nx, sin(angle * 0.5) * ny, sin(angle * 0.5) * nz)

Then from there you could get the matrix or use a direct vector quaternion multiplication function. I could be wrong, but it seems to work for me.

[Edited by - jovani on July 10, 2005 10:21:07 AM]

Share this post


Link to post
Share on other sites
Hey guys thanks,

I got it working now, ended up nothing wrong with my create matrix of rotation around axis function, just that I was crossing vectors right handed in a left handed system, everything kept coming out backwards... lol

thanks for your time everyone

code mole

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this