quat_mult.h 892 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef IGL_QUAT_MULT_H
  2. #define IGL_QUAT_MULT_H
  3. namespace igl
  4. {
  5. // Computes out = q1 * q2 with quaternion multiplication
  6. // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w),
  7. // such that q = x*i + y*j + z*k + w
  8. // Inputs:
  9. // q1 left quaternion
  10. // q2 right quaternion
  11. // Outputs:
  12. // out result of multiplication
  13. inline void quat_mult(
  14. const double *q1,
  15. const double *q2,
  16. double *out);
  17. };
  18. // Implementation
  19. // http://www.antisphere.com/Wiki/tools:anttweakbar
  20. inline void igl::quat_mult(
  21. const double *q1,
  22. const double *q2,
  23. double *out)
  24. {
  25. out[0] = q1[3]*q2[0] + q1[0]*q2[3] + q1[1]*q2[2] - q1[2]*q2[1];
  26. out[1] = q1[3]*q2[1] + q1[1]*q2[3] + q1[2]*q2[0] - q1[0]*q2[2];
  27. out[2] = q1[3]*q2[2] + q1[2]*q2[3] + q1[0]*q2[1] - q1[1]*q2[0];
  28. out[3] = q1[3]*q2[3] - (q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2]);
  29. }
  30. #endif