slicer4ever 6771 Report post Posted July 24, 2011 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. 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted July 24, 2011 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. 0 Share this post Link to post Share on other sites
alvaro 21273 Report post Posted July 24, 2011 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. 0 Share this post Link to post Share on other sites
Dave Eberly 1173 Report post Posted July 24, 2011 Here is one way to deal with [url="http://www.geometrictools.com/Documentation/ConstrainedQuaternions.pdf"]constrained quaternions[/url] . 0 Share this post Link to post Share on other sites
slicer4ever 6771 Report post Posted July 25, 2011 [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. 0 Share this post Link to post Share on other sites