axis_angle_to_quat.cpp 903 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "axis_angle_to_quat.h"
  2. #include "EPS.h"
  3. #include <cmath>
  4. // http://www.antisphere.com/Wiki/tools:anttweakbar
  5. template <typename Q_type>
  6. IGL_INLINE void igl::axis_angle_to_quat(
  7. const Q_type *axis,
  8. const Q_type angle,
  9. Q_type *out)
  10. {
  11. Q_type n = axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2];
  12. if( fabs(n)>igl::EPS<Q_type>())
  13. {
  14. Q_type f = 0.5*angle;
  15. out[3] = cos(f);
  16. f = sin(f)/sqrt(n);
  17. out[0] = axis[0]*f;
  18. out[1] = axis[1]*f;
  19. out[2] = axis[2]*f;
  20. }
  21. else
  22. {
  23. out[3] = 1.0;
  24. out[0] = out[1] = out[2] = 0.0;
  25. }
  26. }
  27. #ifndef IGL_HEADER_ONLY
  28. // Explicit template specialization
  29. // generated by autoexplicit.sh
  30. template void igl::axis_angle_to_quat<double>(double const*, double, double*);
  31. // generated by autoexplicit.sh
  32. template void igl::axis_angle_to_quat<float>(float const*, float, float*);
  33. #endif