Quaternion issue

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Maci
Posts: 3
Joined: Mon Jul 15, 2019 8:30 am

Quaternion issue

Post by Maci » Tue Jul 23, 2019 1:09 pm

Hi all,
I have the following code fragment;

Code: Select all

            var body = new BodyReference(BodyHandle, characters.Simulation.Bodies);
            ref var pose = ref body.Pose;
            pose.Orientation = Quaternion.CreateFromYawPitchRoll(input.CameraAngle, 0, 0);
            Quaternion.TransformUnitZ(pose.Orientation, out var viewDirection);
            Quaternion.GetAxisAngleFromQuaternion(pose.Orientation, out var axis, out var angle);
            Console.WriteLine($"CS:{input.CameraAngle} VD:{viewDirection} A:{axis} ANGLE:{angle}");
I get the following sample output:
CS:90.15236 VD:<0.8156362, 0, -0.5785651> A:<0, 1, 0> ANGLE:2.187765
CS:96.18495 VD:<0.9336317, 0, -0.3582342> A:<0, 1, 0> ANGLE:1.937172
CS:128.3905 VD:<0.4029752, 0, -0.9152108> A:<0, 1, 0> ANGLE:2.726827
CS:144.3713 VD:<-0.1414784, 0, 0.9899414> A:<0, -1, 0> ANGLE:0.1419543

Why is my angle variable wildly different from input.CameraAngle? If I create a Quaternion using CreateFromYawPitchRoll() and then invoke Quaternion.GetAxisAngleFromQuaternion() shouldn't I get the same numbers?
I'm confused...

Maci

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

Re: Quaternion issue

Post by Norbo » Tue Jul 23, 2019 10:32 pm

Orientation quaternions don't distinguish between 2 * PI and 164 * PI, since they correspond to the same orientation. It's also worth noting that all angles are in terms of radians, not degrees.

Note that (128.3905 % PI) ~= 2.726827.

Maci
Posts: 3
Joined: Mon Jul 15, 2019 8:30 am

Re: Quaternion issue

Post by Maci » Wed Jul 24, 2019 7:08 am

I had completely missed that angles were in radians...
Shame on me...

Maci

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

Re: Quaternion issue

Post by Norbo » Wed Jul 24, 2019 9:19 pm

It's okay, you're not the first, nor will you be the last :P

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 62 guests