NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
rodriguesRotation.hpp
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
32 #include "NumCpp/Vector/Vec3.hpp"
33 
34 #include <cmath>
35 
36 namespace nc
37 {
38  namespace rotations
39  {
40  //============================================================================
41  // Method Description:
51  inline Vec3 rodriguesRotation(const Vec3& k, double theta, const Vec3& v) noexcept
52  {
53  const auto kUnit = k.normalize();
54 
55  const auto vCosTheta = v * std::cos(theta);
56 
57  auto kCrossV = kUnit.cross(v);
58  kCrossV *= std::sin(theta);
59 
60  const auto kDotV = kUnit.dot(v);
61  auto kkDotV = kUnit * kDotV;
62  kkDotV *= 1 - std::cos(theta);
63 
64  auto vec = vCosTheta + kCrossV;
65  vec += kkDotV;
66 
67  return vec;
68  }
69 
70  //============================================================================
71  // Method Description:
81  template<typename dtype>
83  {
84  return rodriguesRotation(Vec3(k), theta, Vec3(v)).toNdArray();
85  }
86  } // namespace rotations
87 } // namespace nc
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
Holds a 3D vector.
Definition: Vec3.hpp:50
NdArray< double > toNdArray() const
Definition: Vec3.hpp:323
Vec3 normalize() const noexcept
Definition: Vec3.hpp:275
Vec3 rodriguesRotation(const Vec3 &k, double theta, const Vec3 &v) noexcept
Definition: rodriguesRotation.hpp:51
Definition: Coordinate.hpp:45
auto sin(dtype inValue) noexcept
Definition: sin.hpp:51
auto cos(dtype inValue) noexcept
Definition: cos.hpp:51