normalize_quat.cpp 512 B

1234567891011121314151617181920212223242526272829
  1. #include "normalize_quat.h"
  2. #include "EPS.h"
  3. template <typename Q_type>
  4. IGL_INLINE bool igl::normalize_quat(
  5. const Q_type *q,
  6. Q_type *out)
  7. {
  8. // Get length
  9. Q_type len = sqrt(
  10. q[0]*q[0]+
  11. q[1]*q[1]+
  12. q[2]*q[2]+
  13. q[3]*q[3]);
  14. // Noramlize each coordinate
  15. out[0] = q[0]/len;
  16. out[1] = q[1]/len;
  17. out[2] = q[2]/len;
  18. out[3] = q[3]/len;
  19. // Test whether length was below Epsilon
  20. return (len > igl::EPS<Q_type>());
  21. }
  22. #ifndef IGL_HEADER_ONLY
  23. // Explicit template specialization
  24. #endif