Integrate angular velocity as quaternion rotation
Asked Answered
D

2

7

I have (somewhat blindly) been using quaternions for rotations in physics rigid body simulation for a while, but recently started getting confused about how quaternion rotations are generally defined and how I do it (based on the book Physics for game developers).

In the book you have an angular velocity angVel and a time step dt as well as an initial orientation.

It steps as follows

orientation += 0.5*orientation*angVel * dt

where the quaternion-vector multiplication is done by first converting the vector xyz to the quaternion xyz,0

This works, but everywhere else the procedure is instead to make a quaternion, which defines the time integrated angVel, over dt, and then multiply it on orientation. It essentially converts angVel*dt into a rotation (as makes perfect sense) which is then applied to the original orientation through multiplication, as seen here with better syntax https://math.stackexchange.com/questions/39553/how-do-i-apply-an-angular-velocity-vector3-to-a-unit-quaternion-orientation

My question is what 0.5 * quaternion * vector * scalar conceptually is in the above and what adding this resulting quaternion to my orientation is, considering you usually multiply, and not add, to rotate.

Dorser answered 24/10, 2017 at 10:38 Comment(4)
Check this answer #24197682Corroboration
Thanks that does seem to answer it, yes. Turns out the version I just used out of the box was in fact an approximation. I was very aware that it had no sin and cos, so it sure did seem faster. Thanks for pointing me in that direction. Will give your previous answer an up vote :-)Dorser
On second thought, perhaps not. You give a reasoning for the origin of the delta rotation quaternion, but in my example this is added to the original while you would multiply yours to the original, right?Dorser
You can try to expand quaternion multiplication with delta rotation to receive your form with addition.Corroboration
D
12

To close this properly, I will expand on the comment by minorlogic here.

The time derivative of a rotation quaternion q due to an angular velocity v is given as

dq/dt = 0.5*q*v

Here v is a defining angular velocity in the form where the vector direction defines the axis of rotation and the magnitude defines the speed of rotation. v is further given in in "local space". Had v been in "world space", the multiplication order of q and v would be reversed.

Then the questions expression

orientation += 0.5*orientation*angVel * dt

turns out to just be a normal first order integration over time using this time derivative. It is, however, not very accurate and requires constant re-normalization of the orientation quaternion, but it simple and fast and uses neither sin or cos as axis angle conversions does.

The accuracy issue and normalization requirement can be explained by seeing the unit quaternions, which a proper rotation must be, as points laying on a 4d sphere and the derivative as vectors perpendicular to this sphere surface. As is evident, if you simply add such a vector to such a point on the surface, you get a new point which is no longer on the surface, but slightly above. How slightly depends on the magnitude of this vector and the time step you multiply to your derivative vector. This then requires normalization to put it back on the surface.

To explicitly answer the question. The multiplicative method is used when you have an orientation and a known rotation quaternion to rotate that with, while the additive method is trying to reach the same goal by first order integration of the derivative instead.

Dorser answered 25/10, 2017 at 5:43 Comment(0)
S
1

See this answer -- the code you gave is a 1st order Taylor series expansion of quaternion exponentiation, which is used to integrate the angular velocity over the discrete time interval dt. You can use the other code example in that post (the first code example) if you want a more accurate way to convert angular velocities into rotations, using actual quaternion exponentiation, rather than the Taylor series approximation.

See this derivation if you are interested in the math.

Settlement answered 1/11, 2019 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.