# Rotating a Point around a given Axis

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

## 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 on other sites
This is a reasonable description of the process.

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

code mole

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 24
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013373
×