# Incremental Yaw/Pitch/Roll

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

## Recommended Posts

Hi,
I'm trying to yaw / pitch / roll as an incremental twist along a bezier patch.
Each of the 4 curves of the patch has it's own transform as shown here:

The image shows a yaw of -15 degrees, so curve 1, 2, and 3 are rotatated 5, 10, and 15 degrees respectively, relative to curve 0 (point 0).

The anchor of the rotation depends on whether the yaw / roll is positive or negative, eg. a negative yaw uses curve 0, point 0 as the anchor, while a positive yaw uses curve 0, point 3 as the anchor. The pitch anchor can be any point on curve 0.

The angle for the yaw / pitch / roll is entered in degrees through the gui. Each curve tracks it's rotations so I can do relative rotations.

I've kindof got it working, but if I undo my rotations in a different order I don't end up exactly where i started.
eg. Yaw: 15 -> Pitch 15 -> Roll 15 -> Roll 0 -> Pitch 0 -> Yaw 0 does not get me back to the same place (although its not very far off).

I realise that this is because rotations have to be multiplied in the correct order, but since the anchor for each rotation is potentially different, I can't figure out how to combine the rotations to remain consistant.

For each curve I:
1. Offset the curves position relative to the anchor.
2. Rotate the position relative to the anchor.
3. Offset the position back.
4. Apply the rotation to the curve.

I hope I've explained the problem well enough, and would appreciate any advice.

Cheers,
Nat.

##### Share on other sites
I am not sure I completely understand your situation, but I can tell you that interpolating between rotations by linearly interpolating Euler angles is a really bad idea. What works much better is representing the rotations as quaternions and using slerp to interpolate between them. If you have to enter your rotations as Euler angles in some GUI, you could convert the quaternions back to Euler angles for that purpose.

##### Share on other sites

I've kindof got it working, but if I undo my rotations in a different order I don't end up exactly where i started.
eg. Yaw: 15 -> Pitch 15 -> Roll 15 -> Roll 0 -> Pitch 0 -> Yaw 0 does not get me back to the same place (although its not very far off).

a classic case of floating point error in a flight sim situation

they don't exactly 'Undo" do to floating point error.

quats won't induce error as quickly, but suffer the same issue as mats.

and this has absolutely nothing to do with interpolation. its a numerical methods hardware limitation issue.

needless to say, there are work-arounds, but they're non-trivial.

##### Share on other sites

I would disagree that this is a floating point error issue. After only six rotations, the floating point error is still in the 0.000001 or less of a radian and not discernible.

Not sure what the real problem is though. But with the proper matrix math it will come back to where it was.

here is a little routine I used to make sure:

    float yaw, pitch, roll;
yaw = pitch = roll = MathHelper.ToRadians(15);

Matrix m = Matrix.Identity;

m *= Matrix.CreateRotationY(yaw);
m *= Matrix.CreateRotationX(pitch);
m *= Matrix.CreateRotationZ(roll);
m *= Matrix.CreateRotationZ(-roll);
m *= Matrix.CreateRotationX(-pitch);
m *= Matrix.CreateRotationY(-yaw);


The values of m after are essentially right back where it started, except for the floating point error which are miniscule.

before	after
M11:1	M11:1
M12:0	M12:-1.462545E-08
M13:0	M13:0
M14:0	M14:0
M21:0	M21:-1.143128E-08
M22:1	M22:0.9999999
M23:0	M23:1.290801E-08
M24:0	M24:0
M31:0	M31:-1.336002E-08
M32:0	M32:-7.70093E-09
M33:1	M33:0.9999999
M34:0	M34:0
M41:0	M41:0
M42:0	M42:0
M43:0	M43:0
M44:1	M44:1


Can you post the code of how you are doing the rotation math. Are you using a framework or library? Are you feeding it rotation axis vectors & if so, are you normalizing them first?

Edited by shazen

• 9
• 17
• 10
• 11
• 18