# quaternion, find pitch

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

## 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.

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 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
a . b == |a| * |b| * cos( <a,b> )
you'll get
a[sub]y[/sub] = cos( <a,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 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 on other sites
Here is one way to deal with constrained quaternions .

##### 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
a . b == |a| * |b| * cos( <a,b> )
you'll get
a[sub]y[/sub] = cos( <a,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.

wow, that was...so simple, thanks a billion, now i can limit in any direction, and optimize it to work directly with a quaternion.

1. 1
Rutin
19
2. 2
3. 3
JoeJ
15
4. 4
5. 5

• 23
• 20
• 11
• 13
• 17
• ### Forum Statistics

• Total Topics
631698
• Total Posts
3001770
×