NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
rodriguesRotation.hpp
Go to the documentation of this file.
1 #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
nc::NdArray< double >
nc::cos
auto cos(dtype inValue) noexcept
Definition: cos.hpp:51
nc::rotations::rodriguesRotation
Vec3 rodriguesRotation(const Vec3 &k, double theta, const Vec3 &v) noexcept
Definition: rodriguesRotation.hpp:51
NdArray.hpp
Vec3.hpp
nc::sin
auto sin(dtype inValue) noexcept
Definition: sin.hpp:51
nc
Definition: Coordinate.hpp:44
nc::Vec3::toNdArray
NdArray< double > toNdArray() const
Definition: Vec3.hpp:323
nc::Vec3
Holds a 3D vector.
Definition: Vec3.hpp:49
nc::Vec3::normalize
Vec3 normalize() const noexcept
Definition: Vec3.hpp:275