Sign in to follow this  

quaternion, find pitch

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello all, i'm having a problem in determining the pitch of my quaternion, basically what i need is to know how far i'm looking up/down.

basically i know my order of rotation as x, y, and z, x for pitch, y for heading, and z for roll, and right now i'm converting to euler, however the problem with euler is that as i rotate around the y axis, my pitch switchs from the x component, to the z component, which makes sense i suppose.

basically, how do i find my absolute orientation looking up.

thanks in advance.

note: my end goal is to limit my quaternion by not allowing it to look up/down a certain amount. and i don't want to have to store it another variable if possible.

Share this post


Link to post
Share on other sites
I don't know if there is a standard way of doing this kind of thing, but AFAIK there is no way to limit the quaternion directly.

If you compute the corresponding rotation matrix you can check the angle between the forward vector (e.g. z) and the global horizontal plane (e.g. x-z plane), or alternatively the angle between the up vector (e.g. y) and the global up vector. In the latter case due to
[b]a[/b] . [b]b[/b] == |[b]a[/b]| * |[b]b[/b]| * cos( <[b]a[/b],[b]b[/b]> )
you'll get
a[sub]y[/sub] = cos( <[b]a[/b],[b]b[/b]> )
so that
cos[sup]-1[/sup]( a[sub]y[/sub] )
may be used as the pitching angle. If it exceeds a given limit L, then compute another up vector with
a[sub]y[/sub]' := cos( L )
and the same heading as before. Then use the cross product to compute the corresponding forward vector by keeping the same side vector. That should give you the limited basis matrix. You can convert it then back to a quaternion if desired.

Share this post


Link to post
Share on other sites
If you take your "forward" vector and rotate it using the quaternion, you'll get a vector that tells you where you are aiming. The z component will tell you if you are heading too far down or up. You can then compute another vector that is the desired place to aim and then change your quaternion to point there, using a small rotation.

Share this post


Link to post
Share on other sites
[quote name='haegarr' timestamp='1311511688' post='4839571']
I don't know if there is a standard way of doing this kind of thing, but AFAIK there is no way to limit the quaternion directly.

If you compute the corresponding rotation matrix you can check the angle between the forward vector (e.g. z) and the global horizontal plane (e.g. x-z plane), or alternatively the angle between the up vector (e.g. y) and the global up vector. In the latter case due to
[b]a[/b] . [b]b[/b] == |[b]a[/b]| * |[b]b[/b]| * cos( <[b]a[/b],[b]b[/b]> )
you'll get
a[sub]y[/sub] = cos( <[b]a[/b],[b]b[/b]> )
so that
cos[sup]-1[/sup]( a[sub]y[/sub] )
may be used as the pitching angle. If it exceeds a given limit L, then compute another up vector with
a[sub]y[/sub]' := cos( L )
and the same heading as before. Then use the cross product to compute the corresponding forward vector by keeping the same side vector. That should give you the limited basis matrix. You can convert it then back to a quaternion if desired.
[/quote]
wow, that was...so simple, thanks a billion, now i can limit in any direction, and optimize it to work directly with a quaternion.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this