Rotating an object correctly when you can only rotate world axis.

715 Views Asked by At

This question may be useful to some people, but it is not posed correctly for my particular situation, please see:
Simulating simultaneous rotation of an object about a fixed origin given limited resources.


So, I am using the Processing programming language to create an animation where a box rolls around the screen. The tricky part is that the box can be moving in the X and the Y directions at the same time.

I am drawing the box by simply calling a function called box(), so I am not calculating the vertices based on rotation and then drawing the shape, rather, I am performing a rotation of the coordinate system itself and then drawing a box.

The problem here is that processing only lets you rotate about the world axis, so as much as I would like to do, say: rotateY(radians(60)), rotateX(radians(30)) to rotate the box 60 degrees to the right and then 30 degrees up, calling rotateY() also shifts the X axis itself, so you don't get what you want.

I am looking to derive a trigonometric relationship (likely by taking advantage of the third axis, Z, which you normally wouldn't need to rotate) that I can use in order to simulate the rotation of an object about a fixed set of axis.

Let me try to use some examples to show you what I mean:

So this is what the box looks like if it is not rotated at all. There is also a Z axis, which I have drawn in blue, but you can't see it because of the angle. When the box is rotated it will become visible.

enter image description here

If, before I draw the box, I call:

rotateY(radians(60));
rotateX(radians(30));

I get:

enter image description here

Again, this is because when I rotated about the Y axis the relative angle of the X axis was shifted , so after the call to rotateY(radians(60)) the axes were effectively like this:

enter image description here

I want to derive a relationship that I can use to simulate a way of rotation such that after performing rotateY(radians(60)) the axis would effectively look like(drawing this one with paint:

enter image description here

To clarify, I don't care what the axes actually look like, I only want the end result to be equivalent to what it would be if the axes existed as they do in the picture above.

Again, I think this is possible if I utilize the third axis somehow as a way of correcting the rotation, but I am not sure how to go about it. I have been trying at it for a while now and I can't seem to get something that works across all situations.

You don't need to know programming to solve this. I am looking for some mathematical theories/formulas that I can use to my advantage.

Thanks in advance, hopefully the pictures make it clear. Please don't hesitate to ask me to clarify.

1

There are 1 best solutions below

7
On

It looks like you have access to a function that will perform a rotation about the axes that are aligned with your object. If you want to rotate about an axis as it is in the initial configuration, you should conjugate your rotation.

Let's say you first rotate by $R_y(\theta)$ about the $y$ axis (aligned with the object in the initial configuration). If you then want to rotate about the $x$ axis as it was in the initial configuration, instead of applying $R_x(\phi)$, you should apply $R_y(\theta) R_x(\phi) R^{-1}_y(\theta)$. The full rotation then becomes $$R_y(\theta) R_x(\phi) R_y^{-1}(\theta) R_y(\theta) = R_y(\theta) R_x(\phi)$$ i.e. the order is reversed.

If this doesn't work, try the physics stackexchange; they know about reference frames. Also, see: http://en.wikipedia.org/wiki/Active_and_passive_transformation http://en.wikipedia.org/wiki/Rotation_(mathematics)