# Rotation around X and Z axis only

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

## Recommended Posts

Hi! This might seem like a pretty trivial bit of maths, but I've been messing with rotations all day and now I can't seem to figure this one out. Essentially, I'd like to rotate a point P around another point (let's say the origin, O) in only two of three axes, X, Y and Z. The point being rotated only wants to move around the X and Z axes, giving vertical movement. Unfortunately, at the moment what I've got gives me a strange rotation about both axes, but isn't consistent. It just takes me round in circles. I'm using a rotation matrix to rotate around 3 axes separately at the moment. Tried rotation around an arbitrary axis and it gave me the same result. I've tried some funky things with the sin and cos functions, but so far no luck.
// Rotate and make the camera look back at the centre of the subject
Vector4f pos = position;
pos.Normalise();
rotationX.MakeRotationMatrixX(dt);
rotationZ.MakeRotationMatrixZ(dt);
rotationX.Multiply(rotationZ);
position = position.Multiply33f(rotationX);
cameraPtr->SetPosition(position, entitySubject->GetPosition());



##### Share on other sites
What's the problem? If you rotate uniformly about the X and Z axes, you will travel in a circle. If someone showed me a particle rotating arbitrarily about two axes, then the same on three, I wouldn't be able to tell the difference. In fact, any unitary rotation of a point that can be described in XYZ rotations can also be described in XZ (this is why both yaw-pitch-roll and geocentric rotations are viable in general 3D).

Tell us what you're trying to achieve and what you're actually seeing. You may just be solving the wrong problem the wrong way [wink].

##### Share on other sites
Sorry, I understand that post was a little bit vague! I did a little ASCII diagram to go with it and then realised that the forum wouldn't let me post it. I've implemented my own camera class with pitch, roll, yaw etc so I have an understanding some of the basic principles... so here's the problem.

I have a point. Let's imagine the camera is at this point in space. It is facing the origin. I'm trying to rotate it around the origin but want it only to move in a direction along the X and Z components of the vector between the point and the origin. Up is always (0, 1, 0). The scalar distance between the point and the origin should remain the same. I already have a matrix transformation class which can describe rotation along any one or all of the three axes. If possible I'd like to use just one transformation to describe what I'm trying to do. This would be easy enough to do around one axis, but because the camera can rotate around the origin (or whichever other point I'm using) along the Y axis, it's not just using the X or the Z component of the vector to work out the movement, but both.

Instead of travelling straight along the direction of the X and Z components, the point the camera is at veers off to the side.

1.            y            |            |       ^   \|     --|----O-----> x       o   / \         |  /   \         |'/     z       |/2.      /     o   y     |   |     |   |     |  \|    -|---O-----> x     |'/  \       |/    z3.             /     point o          |          |          |        \ |         \|     -----O-----> x                       zMOTION ALONG BOTH X AND Z AXIS(although it's hard to show using ascii)

[Edited by - PRO_Muffy on May 19, 2007 8:33:57 AM]

##### Share on other sites
No need to apologise.

Edit: I think I misunderstood. Here's what I originally wrote:

Quote:
 Original post by AdmiralNow I see what you mean (I believe), but I think it's a little more complicated than you give it credit for. The camera's position needs to be rotated fully, but its orientation has a fixed y-component. Maybe somebody can suggest something elegant and wonderful, but here's what I would do:If the camera is initially facing the origin, as projected onto the XZ plane, and you only rotate it about the origin, then it will always face the origin under that projection. So together with what you specified, we have the following invariants:1. The camera is always a distance R from the origin.2. The camera's up is always(0, 1, 0).3. When projected to y = 0, the camera always faces the origin.So the operation goes like this:1. Rotate the camera using the full set of Euler angles. It will now be in the right position, but face the wrong direction. In particular, it will have rolled backwards or forwards a little. 2. Set the camera's orientation.y = 1. Now up is up, but we're still looking in the right direction along the XZ plane.3. Normalise the camera's orientation, if necessary.Was that what you were looking for?

As I understood it, you wanted the camera to be free to move anywhere, but for it only ever to look along the XZ plane. After re-reading your last post, it sounds more like you want the motion to be entirely restricted to this plane, so that camera.y is always fixed. If this is the case, then things are simpler; you're just doing it exactly wrong [wink].

If you want the point to rotate without moving off its horizontal plane, you must remove the X and Z components of the rotation (roll and pitch), and use only the Y (yaw). In this way, the point only ever rotates around the y-axis, and so can never leave its horizontal plane.

##### Share on other sites
I think you were a little bit closer the first time around. I've already got a separate rotation for the Y axis and have no trouble rotating the camera around the origin in that plane. That's what I meant before by saying it was easy if I was doing it only around the one axis. The Y component of the camera's position does change. Rotation around the Y axis is actually what causes the problem. If I was 90 degrees to either of the X or Z axis I could just rotate around the other. I'll try do another diagram to illustrate...

LOOKING FROM ABOVE1.           z                          ^                          |                          |                          |                          |               -----------+----------> x            /|                      L / |                       /  |                      /   |                     o    |                   P(x,z)                 2.           z                          ^                          |                          |                          |                          |               -----------+----------> x          L /|                        / |                       o  |                   P(x,z) |                          |

In the first image, the point could well be at a height of 0 on the Y plane. Perhaps think of it more like this. Because the length of L is always the same, the closer the point is pulled toward (0, Y, 0) the higher (or lower) the point gets. The camera's path would be modelled like the arc of a circle around the origin. L is always the same length because the point is either higher or lower on the Y axis. The point's direction of travel is actually along the X and Z vector components toward the centre.

However, using the rotation I have at the moment the camera goes up and toward the centre until it starts to veer off. I'd end up in the top left quadrant going in the opposite vertical direction I started off in...

And now I just had a thought. If I'm trying to rotate like that, I want to be rotating about a 2D vector at right angles to the X and Z component that is created from the point to the origin. And after testing... I tried rotating about (-1.0 / X) and (-1.0 / Z) but to no avail.

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632952
• Total Posts
3009428
• ### Who's Online (See full list)

There are no registered users currently online

×