Coordinate System and Rotation Confusion

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
skyflashde
Posts: 5
Joined: Mon Apr 28, 2014 8:29 am

Coordinate System and Rotation Confusion

Post by skyflashde »

Hi, I am getting my feet wet with BEPU, but I am thoroughly confusing myself with the coordinate system setup. Stuff is just not working, at all.

I have in the background a GIS, which outputs and accepts Lat/Long/Altitude and Heading/Pitch/Bank. I want to have an aircraft moving over the terrain (but not flying, really).

So what I am doing first is to convert Lat/Long/Alt to a position Vector3:

------------------
Pos = new BEPUutilities.Vector3((float)(StaticHelpers.NauticalMileToMeter(Longitude * 60 * Math.Cos(StaticHelpers.DegreeToRadian(-Latitude)))), (float)(StaticHelpers.FeetToMeter(Altitude)), (float)(StaticHelpers.NauticalMileToMeter(-Latitude * 60)));
------------------

The coordinate system is XNA I understand, so I made Longitude = X axis, Altitude = Y axis and Latitude = Z axis. The two conversions seem to be working, I tried out different Lat/Lon/Alt and I got the correct values I expect in the Vector3. And the way back works as well. (I am not even worried about +/- or scale at this point, really)

Next I also have to convert the rotations back and forth. My code to convert into Quaternion is this:

------------------
Rot = BEPUutilities.Quaternion.CreateFromYawPitchRoll((float)DegreeToRadian(-yaw), (float)DegreeToRadian(-pitch), (float)DegreeToRadian(-roll));
------------------

So this should hopefully give me a quaternion where yaw is around the Y axis if it is consistent with the XNA system? The conversion back is working in the same way, and I have confirmed that whatever I am putting into it I can get back out of it with my backwards conversion.

With that being set up, I expected the rotations to work like this:

Heading = Rotation around world Y axis (as Y is Altitude, pointing upwards)
Pitch = Rotation around aircraft X axis (after Heading rotation)
Bank = Rotation around aircraft Z axis (after Heading and Pitch)

This is my rotation code (for testing, the other one I disabled):

PhysicsEntity.AngularVelocity = new Vector3(0, 1, 0);

And my camera is rotating around the pitch axis, which should not be the case.

I have tons of other problems with the other axis, but as soon as I understand this one, I probably can solve the other ones as well.

From my understanding, setting the AngularVelocity like that should rotate the aircraft around the world Y axis, which is pointing upwards, so it should set the heading.
On a sidenote, in my case, the heading should always rotate in world space. So this is not a yawing motion.

If I understand everything correctly, an aircraft with Yaw Pitch Roll = 0 should have its nose at the positive Z axis and its wings level at the X axis, right?

Please! Tell me what is going on, its driving me insane! :)

SkyFlash
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Coordinate System and Rotation Confusion

Post by Norbo »

------------------
Rot = BEPUutilities.Quaternion.CreateFromYawPitchRoll((float)DegreeToRadian(-yaw), (float)DegreeToRadian(-pitch), (float)DegreeToRadian(-roll));
------------------

So this should hopefully give me a quaternion where yaw is around the Y axis if it is consistent with the XNA system? The conversion back is working in the same way, and I have confirmed that whatever I am putting into it I can get back out of it with my backwards conversion.
While yaw was indeed around the Y axis, there was an inconsistency between the BEPUutilities implementation and XNA. It probably managed to sneak through since BEPUphysics as a whole tends to avoid Euler/Tait-Bryan angles like the plague. But it's fixed.

Now, orientationA is equivalent to orientationB:

Code: Select all

            var orientationA = Quaternion.CreateFromYawPitchRoll(0.5f, 1, 2);

            var yaw = Quaternion.CreateFromAxisAngle(Vector3.Up, 0.5f);
            var pitch = Quaternion.CreateFromAxisAngle(Quaternion.Transform(Vector3.Right, yaw), 1);
            var roll = Quaternion.CreateFromAxisAngle(Quaternion.Transform(Vector3.Backward, Quaternion.Concatenate(yaw, pitch)), 2);
            var orientationB = Quaternion.Concatenate(Quaternion.Concatenate(yaw, pitch), roll);
PhysicsEntity.AngularVelocity = new Vector3(0, 1, 0);

And my camera is rotating around the pitch axis, which should not be the case.

I have tons of other problems with the other axis, but as soon as I understand this one, I probably can solve the other ones as well.

From my understanding, setting the AngularVelocity like that should rotate the aircraft around the world Y axis, which is pointing upwards, so it should set the heading.
On a sidenote, in my case, the heading should always rotate in world space. So this is not a yawing motion.
An angular velocity of (0, 1, 0) would indeed imply a rotation around the world Y axis. If it appears to be rotating around the aircraft's pitch axis, then it is implied that the aircraft's pitch axis is actually aligned with the world Y axis.
If I understand everything correctly, an aircraft with Yaw Pitch Roll = 0 should have its nose at the positive Z axis and its wings level at the X axis, right?
Zero for yaw pitch and roll would imply an identity orientation which means the aircraft would be oriented in world space as it is in local space. So, if in local space the aircraft's nose points along the local positive Z axis and the wings are along the local x axis, then yes.
skyflashde
Posts: 5
Joined: Mon Apr 28, 2014 8:29 am

Re: Coordinate System and Rotation Confusion

Post by skyflashde »

I do not really understand everything that you are saying (:P) but as there seems to have been a bug, I will try it now again without the bug and see if that is less confusing to me now.

I will report back with more confusing questions later. ;)
Post Reply