axis_angle_to_quat.cpp 651 B

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