normalize_quat.cpp 724 B

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