1
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ Why on Earth does the command include "radians" if the axes are being rotated in degrees?? $\endgroup$ Jan 6, 2015 at 18:40
  • $\begingroup$ the respective rotate functions all expect their arguments to be in radians, so I am using a separate function, called radians(), to convert the degrees that I specify to their equivalent values in radians and passing the result to the rotate function. $\endgroup$
    – Luke
    Jan 6, 2015 at 18:42
  • $\begingroup$ I see. I apologize for asking such a trivial question, I'm not familiar with the Processing language. $\endgroup$ Jan 6, 2015 at 18:46
  • 1
    $\begingroup$ Probably, Euler Angles is what you want. You can find relevant mathematics around en.wikipedia.org/wiki/… $\endgroup$ Jan 6, 2015 at 20:23

1 Answer 1

1
$\begingroup$

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)

$\endgroup$
7
  • $\begingroup$ Whats the difference between theta and the one with the vertical line? $\endgroup$
    – Luke
    Jan 6, 2015 at 20:23
  • 1
    $\begingroup$ Theta is the angle that you want your object to rotate about the global y axis, while phi is the angle you want to rotate it about the global x axis. $\endgroup$ Jan 6, 2015 at 20:26
  • $\begingroup$ also you mention I should do an inverse rotation after rotating x, can you give an example of what you mean by that please? I'm sorry I'm not very experienced with math. $\endgroup$
    – Luke
    Jan 6, 2015 at 20:26
  • $\begingroup$ If you did rotateX(phi) rotateY(theta) rotateZ(eta), the inverse would be rotateZ(-eta) rotateY(-theta) rotateX(-phi). However, you don't need that; what my analysis shows is that although you should "conceptually" do an inverse, it cancels the R_y that was there, so all you have to do is rotateX(phi) rotateY(theta) to achieve what you want. $\endgroup$ Jan 6, 2015 at 20:36
  • $\begingroup$ This confuses me. Are you saying that rotating an object about the objects relative axes is equivalent to rotating it about the fixed axis I defined? $\endgroup$
    – Luke
    Jan 6, 2015 at 20:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .