# Coordinate transformations question

1. Jun 21, 2010

### danhumphreys

Hi all,

I've been struggling with this for a couple of days now and am positing a question in the hope that someone can help me out.

I have a global cartesian coordinate system X, Y, Z and a cube with it's centre at (0,0,0) and dimension 1. Hence it's corners are: (0.5, -0.5, 0.5), (-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (0.5, 0.5, 0.5), (0.5, -0.5, -0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5), (0.5, 0.5, -0.5).

The cube is now at an arbitrary position where it's local axes are defined such that local axis x is oriented at angle $$\alpha$$ to global axis X, local axis y is oriented at angle $$\beta$$ to global axis Y, and local axis z is oriented $$\gamma$$ to global axis Z.

How can I determine the new cube coordinates in X, Y, Z? The angles $$\alpha$$, $$\beta$$ and $$\gamma$$ are not the same as the Euler angles, they define the position of the local axes relative to the global ones.

Any help would be very much appreciated.

Dan

2. Jun 21, 2010

This does not make any sense. You must mean angles of rotaton around the X, Y and Z axis or from the vertical, horizontal planes.

I think Euler angles is precisely what you mean and use.

Anyway, here are some equations for computing the new absolute coordinates of a given point in space after translating it a given distance 'M' in a given (α, β, γ) / (heading, elevation, roll) absolute direction.

It's been a long time and I remember I once made a typo writing the doc these came from. Please check they work correctly.

Forward
current x +cos(β)·sin(α)·M
current y +sin(β)·M
current z -cos(β)·cos(α)·M

Backward
current x -cos(β)·sin(α)·M
current y -sin(β)·M
current z +cos(β)·cos(α)·M

Upward
current x -[cos(α)·sin(γ)+sin(α)·cos(γ)·sin(β)]·M
current y +cos(γ)·cos(β)·M
current z +[cos(α)·cos(γ)·sin(β)-sin(α)·sin(γ)]·M

Downward
current x +[cos(α)·sin(γ)+sin(α)·cos(γ)·sin(β)]·M
current y -cos(γ)·cos(β)·M
current z -[cos(α)·cos(γ)·sin(β)-sin(α)·sin(γ)]·M

To the left
current x +[cos(α)·cos(γ)-sin(α)·sin(γ)·sin(β)]·M
current y +sin(γ)·cos(β)·M
current z +[cos(α)·sin(γ)·sin(β)+sin(α)·cos(γ)]·M

To the right
current x -[cos(α)·cos(γ)-sin(α)·sin(γ)·sin(β)]·M
current y -sin(γ)·cos(β)·M
current z -[cos(α)·sin(γ)·sin(β)+sin(α)·cos(γ)]·M

Alternatively, if you know the cube's arbitrary new position beforehand and you don't need to compute it from a direction and travel distance, you can simply move your cube to that position (by adding the new absolute position to all your cube's tips' relative positions) then apply rotations to the points, using their initial relative positions (XI,YI,ZI) from the centre of the cube so that you rotate the cube around its centre.

Code (Text):

[FONT="Courier New"]
v1 = calf*xi+salf*zi;
v2 = calf*zi-salf*xi;
v3 = cbet*yi+sbet*v2;

zr = cbet*v2-sbet*yi;
xr = cgam*v1+sgam*v3;
yr = cgam*v3-sgam*v1;[/FONT]
I've been told these can be written down more efficiently using matrices. I dislike matrices.

salf = $$\sin(\alpha)$$;
calf = $$\cos(\alpha)$$;

etc.

These are global buffers for the sinus and cosinus values of the three Euler angles.

v1, v2, v3 are local value buffers, so you don't compute stuff twice.

You obtain new, rotated coordinates (XR,YR,ZR). Which you add to the absolute position of the cube's centre to get the absolute positions of the rotated cube's tips.

Last edited: Jun 21, 2010
3. Jun 21, 2010

### danhumphreys

I should have made it clearer in my post that I am only considering rotation about the centre of the cube (to begin with).

The Euler angles are defined in this picture here:

http://en.wikipedia.org/wiki/File:Eulerangles.svg

But in my example I've defined $$\alpha$$, $$\beta$$ and $$\gamma$$ as the angles between the local and global axes, i.e. the angles between x and X, y and Y and z and Z respectively. As per the angles defined on this picture:

http://en.wikipedia.org/wiki/File:Change_of_axes.svg

I am not really interested in how the cube is rotated to get to the new position but how I might define the new coordinates as a function of the angles between the global and local axes.

Dan

4. Jun 21, 2010

Still doesn't make any sense. There are an infinite number of local coordinate systems whose X', Y' and Z' axis form given α, β and γ angles with the actual X, Y and Z axis.

That is the reason why Euler angles, who can uniquely and unambiguously define any possible orientation of an object or local coordinate system, are defined as angles of rotation around the Y, X and Z axis and NOT as angles from the absolute X, Y and Z axis of the local coordinate system's X', Y' and Z' axis.

Ok, I'm wrong. Not an infinite number:

Let α, β and γ be the Euler angles that describe the orientation of the local coordinate system vis-a-vis the absolute coordinate system.

Let δ, ε and ζ the angles between Z' and Z, X' and X and Y' and Y.

What we would then have is:

arccos( cos(α) · cos(β) ) = δ
arccos( cos(α) · cos(γ) ) = ε
arccos( cos(β) · cos(γ) ) = ζ

cos(α) · cos(β) = cos(δ)
cos(α) · cos(γ) = cos(ε)
cos(β) · cos(γ) = cos(ζ)

cos(β) = cos(δ) / cos(α)
cos(α) · cos(γ) = cos(ε)
cos(δ) / cos(α) · cos(γ) = cos(ζ)

cos(γ) = cos(ε) / cos(α)
cos(δ) / cos(α) · cos(ε) / cos(α) = cos(ζ)

( cos(δ) · cos(ε) ) / cos(α)2 = cos(ζ)

( cos(δ) · cos(ε) ) / cos(ζ) = cos(α)2

$$\alpha = \arccos \sqrt{ \frac{\cos(\delta) \cdot \cos(\epsilon)}{\cos(\zeta)} }$$

Last edited: Jun 21, 2010
5. Jun 22, 2010

### danhumphreys

Thanks for updating your post. What you have given me now allows me to convert δ, ε and ζ (which I know) to Euler angles α, β and γ (which I don't know). Once I know the Euler angles, I can then apply an Euler rotation matrix to the angles to determine my new coordinates.

Just a couple of questions:

1. Where did you get your theory from?

2. What convention are your Euler angles α, β and γ? There are 12 possible conventions i.e. zyz, xyx, xzx etc. etc.

Dan

6. Jun 22, 2010

1. I deduced it. If you can, please check that it works properly.

It seemed self evident that the angle between Z and Z' is going to be influenced by the Euler angle α of rotation around the Y axis (heading) and the Euler angle β of rotation around the transformed X' axis (elevation).

You can think of α and β as longitude and latitude on a globe. As such, the Z axis would point to the Prime/Greenwich meridian at the Ecuator, south of Ghana and west of Gabon in the Atlantic, from the centre of the globe.

Then δ would be the angle between this place and the point indicated by α longitude and β latitude. So it follows intuitively that δ would be arccos( cos(α) · cos(β) ). The γ angle being the angle of rotation around the transformed (by α and β) Z' axis, it is not going to impact the angle between the transformed Z' axis and the original Z axis.

However, as you said, it does matter if you first apply the heading or longitude and then the elevation or latitude or vice versa. If you do it the other way around you'll have the 'poles' on the Ecuator and the same set of coordinates point to a different place.

However, even though the same longitude and latitude can point to different places on the globe (according to the order in which you apply the rotation transformations around YXZ or XYZ), the angle from those two different places to 0°, 0° will be the same (arccos( cos(α) · cos(β) ) versus arccos( cos(β) · cos(α) )).

This is reflected in the solution:

$$\alpha = \arccos \sqrt{ \frac{\cos(\delta) \cdot \cos(\epsilon)}{\cos(\zeta)} }$$

There are two different solution sets for α, β and γ according to δ, ε and ζ.

The γ angle being the angle of rotation around the transformed Z' axis, it is not going to influence the δ angle between Z and Z'.

Just as δ, the angle between Z' and Z, is unaffected by the γ angle around Z', so too ε, the angle between X' and X, is unaffected by the β angle around X' and ζ, the angle between Y' and Y, is unaffected by the α angle around Y (not Y' because rotation around Y axis is the first rotation to be performed so Y transforms the other axis before they transform it).

We already know the order of the Euler rotations makes no difference as to the δ, ε and ζ angles.

2. α is the angle around the Y axis, β is the angle around the X axis and γ is the angle around the Z axis. Heading, elevation, roll.

What do you need this for?