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