MotionVec.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012-2020 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include "EigenTypedef.h"
8 #include "fwd.h"
9 #include <type_traits>
10 
11 namespace sva
12 {
13 
18 template<typename T>
19 class MotionVec
20 {
21 public:
24 
25  friend class PTransform<T>;
26 
27 public:
29  static MotionVec<T> Zero()
30  {
31  return MotionVec<T>(vector3_t::Zero(), vector3_t::Zero());
32  }
33 
34 public:
35  MotionVec() : angular_(), linear_() {}
36 
41  MotionVec(const vector6_t & vec) : angular_(vec.template head<3>()), linear_(vec.template tail<3>()) {}
42 
47  MotionVec(const vector3_t & angular, const vector3_t & linear) : angular_(angular), linear_(linear) {}
48 
49  // Accessor
51  const vector3_t & angular() const
52  {
53  return angular_;
54  }
55 
58  {
59  return angular_;
60  }
61 
63  const vector3_t & linear() const
64  {
65  return linear_;
66  }
67 
70  {
71  return linear_;
72  }
73 
75  vector6_t vector() const
76  {
77  return ((vector6_t() << angular_, linear_).finished());
78  }
79 
80  template<typename T2>
82  {
83  return MotionVec<T2>(angular_.template cast<T2>(), linear_.template cast<T2>());
84  }
85 
86  // Operators
88  {
89  return MotionVec<T>(angular_ + mv.angular_, linear_ + mv.linear_);
90  }
91 
93  {
94  return MotionVec<T>(angular_ - mv.angular_, linear_ - mv.linear_);
95  }
96 
98  {
99  return MotionVec<T>(-angular_, -linear_);
100  }
101 
103  {
104  angular_ += mv.angular_;
105  linear_ += mv.linear_;
106  return *this;
107  }
108 
110  {
111  angular_ -= mv.angular_;
112  linear_ -= mv.linear_;
113  return *this;
114  }
115 
116  template<typename T2, typename std::enable_if<std::is_arithmetic<T2>::value, int>::type = 0>
117  MotionVec<T> operator*(T2 scalar) const
118  {
119  return MotionVec<T>(scalar * angular_, scalar * linear_);
120  }
121 
122  template<typename T2, typename std::enable_if<std::is_arithmetic<T2>::value, int>::type = 0>
124  {
125  angular_ *= scalar;
126  linear_ *= scalar;
127  return *this;
128  }
129 
130  template<typename T2>
132  {
133  angular_ /= scalar;
134  linear_ /= scalar;
135  return *this;
136  }
137 
138  template<typename T2>
139  MotionVec<T> operator/(T2 scalar) const
140  {
141  return MotionVec<T>(angular_ / scalar, linear_ / scalar);
142  }
143 
145  MotionVec<T> cross(const MotionVec<T> & mv2) const;
146 
148  template<typename Derived>
149  void cross(const Eigen::MatrixBase<Derived> & mv2, Eigen::MatrixBase<Derived> & result) const;
150 
152  ForceVec<T> crossDual(const ForceVec<T> & fv2) const;
153 
155  template<typename Derived>
156  void crossDual(const Eigen::MatrixBase<Derived> & fv2, Eigen::MatrixBase<Derived> & result) const;
157 
159  T dot(const ForceVec<T> & fv2) const;
160 
161  bool operator==(const MotionVec<T> & mv) const
162  {
163  return (angular_ == mv.angular_) && (linear_ == mv.linear_);
164  }
165 
166  bool operator!=(const MotionVec<T> & mv) const
167  {
168  return (angular_ != mv.angular_) || (linear_ != mv.linear_);
169  }
170 
171 private:
172  vector3_t angular_;
173  vector3_t linear_;
174 };
175 
176 template<typename T, typename T2>
177 inline MotionVec<T> operator*(T2 scalar, const MotionVec<T> & mv)
178 {
179  return mv * scalar;
180 }
181 
182 template<typename T>
183 inline std::ostream & operator<<(std::ostream & out, const MotionVec<T> & mv)
184 {
185  out << mv.vector().transpose();
186  return out;
187 }
188 
189 } // namespace sva
sva::MotionVec
Definition: fwd.h:11
sva::operator<<
std::ostream & operator<<(std::ostream &out, const ABInertia< T > &abI)
Definition: ABInertia.h:183
sva::MotionVec::operator/
MotionVec< T > operator/(T2 scalar) const
Definition: MotionVec.h:139
sva::MotionVec::crossDual
ForceVec< T > crossDual(const ForceVec< T > &fv2) const
Definition: Operators.h:132
sva::ForceVec
Definition: ForceVec.h:19
sva::MotionVec::operator*
MotionVec< T > operator*(T2 scalar) const
Definition: MotionVec.h:117
sva::MotionVec::vector6_t
Eigen::Vector6< T > vector6_t
Definition: MotionVec.h:23
sva
Definition: ABInertia.h:10
fwd.h
sva::MotionVec::dot
T dot(const ForceVec< T > &fv2) const
Definition: Operators.h:151
sva::MotionVec::operator==
bool operator==(const MotionVec< T > &mv) const
Definition: MotionVec.h:161
sva::MotionVec::angular
const vector3_t & angular() const
Definition: MotionVec.h:51
sva::MotionVec::operator+
MotionVec< T > operator+(const MotionVec< T > &mv) const
Definition: MotionVec.h:87
sva::MotionVec::linear
vector3_t & linear()
Definition: MotionVec.h:69
Eigen::Vector3
Matrix< T, 3, 1 > Vector3
Definition: EigenTypedef.h:18
sva::MotionVec::MotionVec
MotionVec(const vector3_t &angular, const vector3_t &linear)
Definition: MotionVec.h:47
sva::MotionVec::Zero
static MotionVec< T > Zero()
Zero motion vector.
Definition: MotionVec.h:29
sva::MotionVec::linear
const vector3_t & linear() const
Definition: MotionVec.h:63
sva::MotionVec::vector3_t
Eigen::Vector3< T > vector3_t
Definition: MotionVec.h:22
sva::MotionVec::operator!=
bool operator!=(const MotionVec< T > &mv) const
Definition: MotionVec.h:166
sva::operator*
ABInertia< T > operator*(T2 scalar, const ABInertia< T > &abI)
Definition: ABInertia.h:177
sva::MotionVec::angular
vector3_t & angular()
Definition: MotionVec.h:57
sva::MotionVec::operator+=
MotionVec< T > & operator+=(const MotionVec< T > &mv)
Definition: MotionVec.h:102
sva::MotionVec::operator-
MotionVec< T > operator-(const MotionVec< T > &mv) const
Definition: MotionVec.h:92
Eigen::Vector6
Matrix< T, 6, 1 > Vector6
Definition: EigenTypedef.h:13
sva::MotionVec::operator-=
MotionVec< T > & operator-=(const MotionVec< T > &mv)
Definition: MotionVec.h:109
sva::MotionVec::operator/=
MotionVec< T > & operator/=(T2 scalar)
Definition: MotionVec.h:131
EigenTypedef.h
sva::MotionVec::MotionVec
MotionVec(const vector6_t &vec)
Definition: MotionVec.h:41
sva::MotionVec::MotionVec
MotionVec()
Definition: MotionVec.h:35
sva::PTransform
Definition: fwd.h:23
sva::MotionVec::cast
MotionVec< T2 > cast() const
Definition: MotionVec.h:81
sva::MotionVec::vector
vector6_t vector() const
Definition: MotionVec.h:75
sva::MotionVec::operator*=
MotionVec< T > & operator*=(T2 scalar)
Definition: MotionVec.h:123
sva::MotionVec::operator-
MotionVec< T > operator-() const
Definition: MotionVec.h:97
sva::MotionVec::cross
MotionVec< T > cross(const MotionVec< T > &mv2) const
Definition: Operators.h:113