Rotate around arbitrary axis


I hope someone can help me. I’m trying to work out the coordinates of my object after it’s been rotated around an arbitrary axis, but I’m having problems working out the maths I need to apply.

I know it’s very easy to rotate around a fixed axis, e.g. the Z axis with the vector 0,0,1, by using:

x’ = xcos q - ysin q
y’ = xsin q + ycos q
z’ = z

But what if, for example, you have an axis around the vector: 0, 0.7071607, 0.7071607 (i.e. 45 degrees between Y and Z).

You can’t use a simple rotation matrix like the one above because it won’t do the same thing!

So how exactly do you work it out?! I’m going out of my mind…

Any help appreciated. :slight_smile:



Dude, this is what glRotate does.

Look up the formula in the OpenGL Programming Guide or the OpenGL specs chapter 2.11.

If you have problems with that notation, “I” means a 3x3 identity matrix and uuT is a three component column(!) vector multiplied by its row-vector counterpart giving a 3x3 matrix. (That’s called an outer multiplication, where a dot-product is an innner multiplication.)

The rotation you’re trying to achieve can be thought of three seperate rotations:

  1. A rotation that places your rotation axis along the Z-axis (rotation A);
  2. A rotation around the Z-axis (rotation B; this is essentially what you have already);
  3. A rotation that places your rotation axis back to its original orientation (rotation C; this is the inverse of rotation A).

If you’re working with matrices, you’re dealing with the product (i.e. the multiplication) of three seperate rotation matrices. You can also make a function for a general rotation (e.g. input is a rotation axis, an angle and a point to rotate; output is the rotated point) and call it for each of the three steps.


OK, thanks for the help.

I know what I need to do, it’s just getting my head round the implementation. :slight_smile: