LetHopeItsSnowing wrote:Your right, my original description of getting a directional vector is what was wrong, I didnt want a direction vector what I wanted was the ability to transform x,y,z co-ordinates based on yaw, pitch and roll.

The easiest way to transform x, y, z coordinates based on yaw, pitch and roll (euler angles) is to use a direction cosine matrix. If you look at the diagram below you can see that it has four axis systems. The (ox3y3z3) axis system is the body axis system and is fixed to your astro pi and will rotate with it. The (ox0y0z0) axis system is the reference axis system, this will probably be relative to the ground depending on how you define it and will not rotate with astro pi. The other two axis systems (ox1y1z1) and (ox2y2z2) and just intermediate axis systems used to transform from the reference axis system to the body axis system.

- euler_angles_small.png (61.1 KiB) Viewed 12830 times

To transform from the reference axis system to the body axis system, three rotations need to be applied to the x, y, z coordinates. First you have to yaw about axis oz0 through the angle Ψ, this will take you from the (ox0y0z0) axis system to the (ox1y1z1) axis system. Then you need to pitch about the oy1 axis through angle θ, this will take you from the (ox1y1z1) axis system to the (ox2y2z2) axis system. Finally roll about axis ox2 through the angle ϕ, this will take you from the (ox2y2z2) axis system to the (ox3y3z3) axis system.

So if we perform the first rotation of yawing about oz0 through the angle Ψ and get:

Or, representing this as a matrix:

Then we perform the second rotation of pitching about oy1 through the angle θ and get:

Or, representing this as a matrix:

Then finally we perform the third rotation of rolling about ox2 through the angle ϕ we get:

Or, representing this as a matrix:

If we repeatedly substitute the above three matrix equations, we get the following expression for perform all three rotations:

Performing the matrix multiplications gives:

So the above equation will rotate x, y, z coordinates in the reference axis system to the body axis system. If you're not too comfortable with matrices, the following equations are equivalent:

If you wish to go the other way around (i.e. from the body axis system to the reference axis system) you need to take the inverse of the big direction cosine matrix in the middle (which for a direction cosine matrix is the same as its transpose):

Again, if you're not too familiar with matrices, the following equations are equivalent:

Sorry this post was so maths heavy, but this really is the proper way to do this so I thought I would try to explain it thoroughly. If you have any questions I'll be happy to help.