normalize_quat.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "normalize_quat.h"
  9. #include "EPS.h"
  10. #include <cmath>
  11. template <typename Q_type>
  12. IGL_INLINE bool igl::normalize_quat(
  13. const Q_type *q,
  14. Q_type *out)
  15. {
  16. // Get length
  17. Q_type len = sqrt(
  18. q[0]*q[0]+
  19. q[1]*q[1]+
  20. q[2]*q[2]+
  21. q[3]*q[3]);
  22. // Noramlize each coordinate
  23. out[0] = q[0]/len;
  24. out[1] = q[1]/len;
  25. out[2] = q[2]/len;
  26. out[3] = q[3]/len;
  27. // Test whether length was below Epsilon
  28. return (len > igl::EPS<Q_type>());
  29. }
  30. #ifdef IGL_STATIC_LIBRARY
  31. // Explicit template instantiation
  32. // generated by autoexplicit.sh
  33. template bool igl::normalize_quat<double>(double const*, double*);
  34. // generated by autoexplicit.sh
  35. template bool igl::normalize_quat<float>(float const*, float*);
  36. #endif