"Distance" (or angular magnitude) between two quaternions?

10,307

Solution 1

Find the difference quaternion qd = inverse(q1)*q2).

Than find the angle between q1 and q2 by angle = 2 * atan2(qd.vec().length(), qd.w()) // NOTE: signed

The "angle" here, is the angle of rotation from q1 to q2 by shortest arc.

Solution 2

Also you can use this lib function from pyquaternion. Quaternion.absolute_distance(q0, q1)

Share:
10,307
Clonkex
Author by

Clonkex

Enjoyer of Overwatch/AoE4/Siege/Mordhau/Chiv2, sort-of-Accordion Player, avid Rollerblader (Seba High Light V1 2015), Christian. Rode a CB500X for a while, but sold it when my car engine cost me 12 grand. Now riding a 2020 Royal Enfield Himalayan (Itchy Boots ftw). Started programming at ~13 in Liberty BASIC. Progressed to DBPro at ~15 (and loved it). Now a decent programmer of many languages living in beautiful country NSW. Came up with my name at 13, when my gaming life was defined by the awesome games Clonk and Cube/Sauerbraten and by emulators like MAME, Gens and SNEX9x. Originally a fan of C++, then of Javascript, but C# is my current favourite. Boop.

Updated on June 05, 2022

Comments

  • Clonkex
    Clonkex almost 2 years

    I want to find the "distance" between two quaternions. By "distance" I mean a single float or int, not another quaternion (that would be the difference, i.e. inverse(q1)*q2). I guess you could call what I want "angular magnitude".

    I need to apply more torque to a physics object the further it's rotated from its original angle.

    I don't understand the maths involved in quaternions, so a code-based example would be most helpful. I've looked at several other questions but I don't believe any answer my question, or at least not in a way I understand it.

  • Clonkex
    Clonkex about 10 years
    Sounds like exactly what I need. I'll test shortly and accept your answer if it is :)
  • Peter
    Peter over 5 years
    Can you explain how you got this equation please?
  • minorlogic
    minorlogic over 5 years
  • Michael T
    Michael T about 5 years
    what does .vec() do?
  • minorlogic
    minorlogic about 5 years
    vec() return vector part of quaternion (x,y,z)