Integrate angular velocity as quaternion rotation

10,007

Solution 1

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.

Solution 2

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.

Share:
10,007
JoeTaicoon
Author by

JoeTaicoon

Working as a freelance developer in areas of mathematical programming and graphics. Holding a MSc in computer science and computational and mathematical modelling with primary focus on fluid dynamics using SPH and FVM as well as computational image analysis.

Updated on June 04, 2022

Comments

  • JoeTaicoon
    JoeTaicoon almost 2 years

    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.