pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
skew.hpp
1//
2// Copyright (c) 2015-2021 CNRS INRIA
3//
4
5#ifndef __pinocchio_spatial_skew_hpp__
6#define __pinocchio_spatial_skew_hpp__
7
8#include "pinocchio/macros.hpp"
9
10namespace pinocchio
11{
12
21 template<typename Vector3, typename Matrix3>
22 inline void skew(const Eigen::MatrixBase<Vector3> & v, const Eigen::MatrixBase<Matrix3> & M)
23 {
26
27 Matrix3 & M_ = PINOCCHIO_EIGEN_CONST_CAST(Matrix3, M);
28 typedef typename Matrix3::RealScalar Scalar;
29
30 M_(0, 0) = Scalar(0);
31 M_(0, 1) = -v[2];
32 M_(0, 2) = v[1];
33 M_(1, 0) = v[2];
34 M_(1, 1) = Scalar(0);
35 M_(1, 2) = -v[0];
36 M_(2, 0) = -v[1];
37 M_(2, 1) = v[0];
38 M_(2, 2) = Scalar(0);
39 }
40
49 template<typename D>
50 inline Eigen::Matrix<typename D::Scalar, 3, 3, PINOCCHIO_EIGEN_PLAIN_TYPE(D)::Options>
51 skew(const Eigen::MatrixBase<D> & v)
52 {
53 Eigen::Matrix<typename D::Scalar, 3, 3, PINOCCHIO_EIGEN_PLAIN_TYPE(D)::Options> M;
54 skew(v, M);
55 return M;
56 }
57
66 template<typename Vector3Like, typename Matrix3Like>
67 inline void
68 addSkew(const Eigen::MatrixBase<Vector3Like> & v, const Eigen::MatrixBase<Matrix3Like> & M)
69 {
71 PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3Like, M, 3, 3);
72
73 Matrix3Like & M_ = PINOCCHIO_EIGEN_CONST_CAST(Matrix3Like, M);
74
75 M_(0, 1) -= v[2];
76 M_(0, 2) += v[1];
77 M_(1, 0) += v[2];
78 M_(1, 2) -= v[0];
79 M_(2, 0) -= v[1];
80 M_(2, 1) += v[0];
81 ;
82 }
83
92 template<typename Matrix3, typename Vector3>
93 inline void unSkew(const Eigen::MatrixBase<Matrix3> & M, const Eigen::MatrixBase<Vector3> & v)
94 {
95 typedef typename Vector3::RealScalar Scalar;
98
99 Vector3 & v_ = PINOCCHIO_EIGEN_CONST_CAST(Vector3, v);
100
101 v_[0] = Scalar(0.5) * (M(2, 1) - M(1, 2));
102 v_[1] = Scalar(0.5) * (M(0, 2) - M(2, 0));
103 v_[2] = Scalar(0.5) * (M(1, 0) - M(0, 1));
104 }
105
115 template<typename Matrix3>
116 inline Eigen::Matrix<typename Matrix3::Scalar, 3, 1, PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3)::Options>
117 unSkew(const Eigen::MatrixBase<Matrix3> & M)
118 {
119 Eigen::Matrix<typename Matrix3::Scalar, 3, 1, PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3)::Options> v;
120 unSkew(M, v);
121 return v;
122 }
123
133 template<typename Scalar, typename Vector3, typename Matrix3>
135 const Scalar alpha, const Eigen::MatrixBase<Vector3> & v, const Eigen::MatrixBase<Matrix3> & M)
136 {
139
140 Matrix3 & M_ = PINOCCHIO_EIGEN_CONST_CAST(Matrix3, M);
141 typedef typename Matrix3::RealScalar RealScalar;
142
143 M_(0, 0) = RealScalar(0);
144 M_(0, 1) = -v[2] * alpha;
145 M_(0, 2) = v[1] * alpha;
146 M_(1, 0) = -M_(0, 1);
147 M_(1, 1) = RealScalar(0);
148 M_(1, 2) = -v[0] * alpha;
149 M_(2, 0) = -M_(0, 2);
150 M_(2, 1) = -M_(1, 2);
151 M_(2, 2) = RealScalar(0);
152 }
153
164 template<typename Scalar, typename Vector3>
165 inline Eigen::Matrix<typename Vector3::Scalar, 3, 3, PINOCCHIO_EIGEN_PLAIN_TYPE(Vector3)::Options>
166 alphaSkew(const Scalar alpha, const Eigen::MatrixBase<Vector3> & v)
167 {
168 Eigen::Matrix<typename Vector3::Scalar, 3, 3, PINOCCHIO_EIGEN_PLAIN_TYPE(Vector3)::Options> M;
169 alphaSkew(alpha, v, M);
170 return M;
171 }
172
181 template<typename V1, typename V2, typename Matrix3>
182 inline void skewSquare(
183 const Eigen::MatrixBase<V1> & u,
184 const Eigen::MatrixBase<V2> & v,
185 const Eigen::MatrixBase<Matrix3> & C)
186 {
190
191 Matrix3 & C_ = PINOCCHIO_EIGEN_CONST_CAST(Matrix3, C);
192 typedef typename Matrix3::RealScalar Scalar;
193
194 C_.noalias() = v * u.transpose();
195 const Scalar udotv(u.dot(v));
196 C_.diagonal().array() -= udotv;
197 }
198
208 template<typename V1, typename V2>
209 inline Eigen::Matrix<typename V1::Scalar, 3, 3, PINOCCHIO_EIGEN_PLAIN_TYPE(V1)::Options>
210 skewSquare(const Eigen::MatrixBase<V1> & u, const Eigen::MatrixBase<V2> & v)
211 {
212
213 Eigen::Matrix<typename V1::Scalar, 3, 3, PINOCCHIO_EIGEN_PLAIN_TYPE(V1)::Options> M;
214 skewSquare(u, v, M);
215 return M;
216 }
217
227 template<typename Vector3, typename Matrix3xIn, typename Matrix3xOut>
228 inline void cross(
229 const Eigen::MatrixBase<Vector3> & v,
230 const Eigen::MatrixBase<Matrix3xIn> & Min,
231 const Eigen::MatrixBase<Matrix3xOut> & Mout)
232 {
235 Matrix3xIn::RowsAtCompileTime == 3, THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
237 Matrix3xOut::RowsAtCompileTime == 3, THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
238
239 Matrix3xOut & Mout_ = PINOCCHIO_EIGEN_CONST_CAST(Matrix3xOut, Mout);
240
241 Mout_.row(0) = v[1] * Min.row(2) - v[2] * Min.row(1);
242 Mout_.row(1) = v[2] * Min.row(0) - v[0] * Min.row(2);
243 Mout_.row(2) = v[0] * Min.row(1) - v[1] * Min.row(0);
244 }
245
254 template<typename Vector3, typename Matrix3x>
255 inline typename PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3x)
256 cross(const Eigen::MatrixBase<Vector3> & v, const Eigen::MatrixBase<Matrix3x> & M)
257 {
258 typename PINOCCHIO_EIGEN_PLAIN_TYPE(Matrix3x) res(3, M.cols());
259 cross(v, M, res);
260 return res;
261 }
262
263} // namespace pinocchio
264
265#endif // ifndef __pinocchio_spatial_skew_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
void skewSquare(const Eigen::MatrixBase< V1 > &u, const Eigen::MatrixBase< V2 > &v, const Eigen::MatrixBase< Matrix3 > &C)
Computes the square cross product linear operator C(u,v) such that for any vector w,...
Definition skew.hpp:182
void addSkew(const Eigen::MatrixBase< Vector3Like > &v, const Eigen::MatrixBase< Matrix3Like > &M)
Add skew matrix represented by a 3d vector to a given matrix, i.e. add the antisymmetric matrix repre...
Definition skew.hpp:68
void cross(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3xIn > &Min, const Eigen::MatrixBase< Matrix3xOut > &Mout)
Applies the cross product onto the columns of M.
Definition skew.hpp:228
void unSkew(const Eigen::MatrixBase< Matrix3 > &M, const Eigen::MatrixBase< Vector3 > &v)
Inverse of skew operator. From a given skew-symmetric matrix M of dimension 3x3, it extracts the supp...
Definition skew.hpp:93
void alphaSkew(const Scalar alpha, const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector multiplied by a given scalar....
Definition skew.hpp:134
void skew(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector, i.e. the antisymmetric matrix representation o...
Definition skew.hpp:22