quat_conjugate.h 746 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef IGL_QUAT_CONJUGATE_H
  2. #define IGL_QUAT_CONJUGATE_H
  3. namespace igl
  4. {
  5. // Compute conjugate of given quaternion
  6. // http://en.wikipedia.org/wiki/Quaternion#Conjugation.2C_the_norm.2C_and_reciprocal
  7. // A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w),
  8. // such that q = x*i + y*j + z*k + w
  9. // Inputs:
  10. // q1 input quaternion
  11. // Outputs:
  12. // out result of conjugation, allowed to be same as input
  13. template <typename Q_type>
  14. inline void quat_conjugate(
  15. const Q_type *q1,
  16. Q_type *out);
  17. };
  18. // Implementation
  19. template <typename Q_type>
  20. inline void igl::quat_conjugate(
  21. const Q_type *q1,
  22. Q_type *out)
  23. {
  24. out[0] = -q1[0];
  25. out[1] = -q1[1];
  26. out[2] = -q1[2];
  27. out[3] = q1[3];
  28. }
  29. #endif