Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quaternion Distance #336

Closed
kevzettler opened this issue Sep 9, 2018 · 5 comments · Fixed by #364
Closed

Quaternion Distance #336

kevzettler opened this issue Sep 9, 2018 · 5 comments · Fixed by #364
Milestone

Comments

@kevzettler
Copy link
Contributor

I'd like to take two quaternions and get a distance value which is the delta between their separate orientations. Any methods to do this I'm overlooking?

@stefnotch
Copy link
Collaborator

You could use the dot product and convert it to an angle. You could also write a function that does this and create a PR.

@jWA86
Copy link

jWA86 commented Sep 9, 2018

const invers = quat.invert(quat.create(), q1);
const diff = quat.multiply(quat.create(), invers, q2);
const radian = quat.getAxisAngle(vec3.create(), diff);

@kevzettler
Copy link
Contributor Author

@stefnotch happy to write a PR but this a beyond my math skills.

How does jWA86's suggestion compare to the dot product idea?

@stefnotch
Copy link
Collaborator

stefnotch commented Nov 7, 2018

@kevzettler

The quaternion dot product approach works as follows: https://www.3dgep.com/understanding-quaternions/#Quaternion_Dot_Product
It's really similar to the vector dot product.

jWA86's approach isn't that complicated either. A quaternion is a rotation, or an axis-angle. And, the multiplication of quaternions represents composing the two rotations: perform one rotation and then perform the other one (1).

So, to get the angle between q1 and q2 he

  • takes the inverse of q1 and
  • multiplies it by q2
  • gets the angle of the result

Effectively, "this takes away the rotation q1 from q2", and then, getting the axis-angle from the result is trivial.

(1): Minor warning: It's not commutative, the order in which you do the multiplication matters.

@stefnotch
Copy link
Collaborator

stefnotch commented Nov 7, 2018

Upon doing further research, you should probably implement jWA86's suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants