quat_mult.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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 "quat_mult.h"
  9. #include <cassert>
  10. // http://www.antisphere.com/Wiki/tools:anttweakbar
  11. template <typename Q_type>
  12. IGL_INLINE void igl::quat_mult(
  13. const Q_type *q1,
  14. const Q_type *q2,
  15. Q_type *out)
  16. {
  17. // output can't be either of the inputs
  18. assert(q1 != out);
  19. assert(q2 != out);
  20. out[0] = q1[3]*q2[0] + q1[0]*q2[3] + q1[1]*q2[2] - q1[2]*q2[1];
  21. out[1] = q1[3]*q2[1] + q1[1]*q2[3] + q1[2]*q2[0] - q1[0]*q2[2];
  22. out[2] = q1[3]*q2[2] + q1[2]*q2[3] + q1[0]*q2[1] - q1[1]*q2[0];
  23. out[3] = q1[3]*q2[3] - (q1[0]*q2[0] + q1[1]*q2[1] + q1[2]*q2[2]);
  24. }
  25. #ifdef IGL_STATIC_LIBRARY
  26. // Explicit template specialization
  27. // generated by autoexplicit.sh
  28. template void igl::quat_mult<double>(double const*, double const*, double*);
  29. // generated by autoexplicit.sh
  30. template void igl::quat_mult<float>(float const*, float const*, float*);
  31. #endif