Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate angular velocity as quaternion rotation

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.

like image 371
JoeTaicoon Avatar asked Oct 24 '17 10:10

JoeTaicoon


1 Answers

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.

like image 196
JoeTaicoon Avatar answered Nov 09 '22 05:11

JoeTaicoon