pinocchio  UNKNOWN
skew.hpp
1 //
2 // Copyright (c) 2015-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_skew_hpp__
19 #define __se3_skew_hpp__
20 
21 #include "pinocchio/macros.hpp"
22 
23 namespace se3
24 {
25 
33  template <typename Vector3, typename Matrix3>
34  inline void skew(const Eigen::MatrixBase<Vector3> & v,
35  const Eigen::MatrixBase<Matrix3> & M)
36  {
37  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3,3);
38  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3,3,3);
39 
40  Matrix3 & M_ = const_cast<Eigen::MatrixBase<Matrix3> &>(M).derived();
41  typedef typename Matrix3::RealScalar Scalar;
42 
43  M_(0,0) = Scalar(0); M_(0,1) = -v[2]; M_(0,2) = v[1];
44  M_(1,0) = v[2]; M_(1,1) = Scalar(0); M_(1,2) = -v[0];
45  M_(2,0) = -v[1]; M_(2,1) = v[0]; M_(2,2) = Scalar(0);
46  }
47 
56  template <typename D>
57  inline Eigen::Matrix<typename D::Scalar,3,3,EIGEN_PLAIN_TYPE(D)::Options>
58  skew(const Eigen::MatrixBase<D> & v)
59  {
60  Eigen::Matrix<typename D::Scalar,3,3,EIGEN_PLAIN_TYPE(D)::Options> M;
61  skew(v,M);
62  return M;
63  }
64 
73  template <typename Matrix3, typename Vector3>
74  inline void unSkew(const Eigen::MatrixBase<Matrix3> & M,
75  const Eigen::MatrixBase<Vector3> & v)
76  {
77  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3,3);
78  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3,3,3);
79  assert((M + M.transpose()).isMuchSmallerThan(M));
80 
81  Vector3 & v_ = const_cast<Eigen::MatrixBase<Vector3> &>(v).derived();
82  typedef typename Vector3::RealScalar Scalar;
83 
84  v_[0] = Scalar(0.5) * (M(2,1) - M(1,2));
85  v_[1] = Scalar(0.5) * (M(0,2) - M(2,0));
86  v_[2] = Scalar(0.5) * (M(1,0) - M(0,1));
87  }
88 
98  template <typename Matrix3>
99  inline Eigen::Matrix<typename EIGEN_PLAIN_TYPE(Matrix3)::Scalar,3,1,EIGEN_PLAIN_TYPE(Matrix3)::Options>
100  unSkew(const Eigen::MatrixBase<Matrix3> & M)
101  {
102  Eigen::Matrix<typename EIGEN_PLAIN_TYPE(Matrix3)::Scalar,3,1,EIGEN_PLAIN_TYPE(Matrix3)::Options> v;
103  unSkew(M,v);
104  return v;
105  }
106 
115  template <typename Scalar, typename Vector3, typename Matrix3>
116  void alphaSkew(const Scalar alpha,
117  const Eigen::MatrixBase<Vector3> & v,
118  const Eigen::MatrixBase<Matrix3> & M)
119  {
120  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3,3);
121  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3,3,3);
122 
123  Matrix3 & M_ = const_cast<Eigen::MatrixBase<Matrix3> &>(M).derived();
124  typedef typename Matrix3::RealScalar RealScalar;
125 
126  M_(0,0) = RealScalar(0); M_(0,1) = -v[2] * alpha; M_(0,2) = v[1] * alpha;
127  M_(1,0) = -M_(0,1); M_(1,1) = RealScalar(0); M_(1,2) = -v[0] * alpha;
128  M_(2,0) = -M_(0,2); M_(2,1) = -M_(1,2); M_(2,2) = RealScalar(0);
129  }
130 
140  template <typename Scalar, typename Vector3>
141  inline Eigen::Matrix<typename Vector3::Scalar,3,3,EIGEN_PLAIN_TYPE(Vector3)::Options>
142  alphaSkew(const Scalar alpha,
143  const Eigen::MatrixBase<Vector3> & v)
144  {
145  Eigen::Matrix<typename Vector3::Scalar,3,3,EIGEN_PLAIN_TYPE(Vector3)::Options> M;
146  alphaSkew(alpha,v,M);
147  return M;
148  }
149 
157  template <typename V1, typename V2, typename Matrix3>
158  inline void skewSquare(const Eigen::MatrixBase<V1> & u,
159  const Eigen::MatrixBase<V2> & v,
160  const Eigen::MatrixBase<Matrix3> & C)
161  {
162  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V1,3);
163  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V2,3);
164  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix3,3,3);
165 
166  Matrix3 & C_ = const_cast<Eigen::MatrixBase<Matrix3> &>(C).derived();
167  typedef typename Matrix3::RealScalar Scalar;
168 
169  C_.noalias() = v*u.transpose();
170  const Scalar udotv(u.dot(v));
171  C_.diagonal().array() -= udotv;
172  }
173 
182  template <typename V1, typename V2>
183  inline Eigen::Matrix<typename V1::Scalar,3,3,EIGEN_PLAIN_TYPE(V1)::Options>
184  skewSquare(const Eigen::MatrixBase<V1> & u,
185  const Eigen::MatrixBase<V2> & v)
186  {
187 
188  Eigen::Matrix<typename V1::Scalar,3,3,EIGEN_PLAIN_TYPE(V1)::Options> M;
189  skewSquare(u,v,M);
190  return M;
191  }
192 
202  template <typename Vector3, typename Matrix3xIn, typename Matrix3xOut>
203  inline void cross(const Eigen::MatrixBase<Vector3> & v,
204  const Eigen::MatrixBase<Matrix3xIn> & Min,
205  const Eigen::MatrixBase<Matrix3xOut> & Mout)
206  {
207  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3,3);
208  EIGEN_STATIC_ASSERT(Matrix3xIn::RowsAtCompileTime==3,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
209  EIGEN_STATIC_ASSERT(Matrix3xOut::RowsAtCompileTime==3,THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE);
210 
211  Matrix3xOut & Mout_ = const_cast<Eigen::MatrixBase<Matrix3xOut> &>(Mout).derived();
212 
213  Mout_.row(0) = v[1]*Min.row(2) - v[2]*Min.row(1);
214  Mout_.row(1) = v[2]*Min.row(0) - v[0]*Min.row(2);
215  Mout_.row(2) = v[0]*Min.row(1) - v[1]*Min.row(0);
216  }
217 
226  template <typename Vector3, typename Matrix3x>
227  inline typename EIGEN_PLAIN_TYPE(Matrix3x)
228  cross(const Eigen::MatrixBase<Vector3> & v,
229  const Eigen::MatrixBase<Matrix3x> & M)
230  {
231  typename EIGEN_PLAIN_TYPE(Matrix3x) res(3,M.cols());
232  cross(v,M,res);
233  return res;
234  }
235 
236 } // namespace se3
237 
238 #endif // ifndef __se3_skew_hpp__
EIGEN_PLAIN_TYPE(Matrix3x) cross(const Eigen
Applies the cross product onto the columns of M.
Definition: skew.hpp:227
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:158
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. i.e. the antisymmetric matrix representation of the cross product operator ( )
Definition: skew.hpp:116
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:34
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:74
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:203