SkewSymmetricMatrix3.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_SKEWSYMMETRICMATRIX3_H
12 #define EIGEN_SKEWSYMMETRICMATRIX3_H
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
33 template<typename Derived>
34 class SkewSymmetricBase : public EigenBase<Derived>
35 {
36  public:
37  typedef typename internal::traits<Derived>::SkewSymmetricVectorType SkewSymmetricVectorType;
38  typedef typename SkewSymmetricVectorType::Scalar Scalar;
39  typedef typename SkewSymmetricVectorType::RealScalar RealScalar;
40  typedef typename internal::traits<Derived>::StorageKind StorageKind;
41  typedef typename internal::traits<Derived>::StorageIndex StorageIndex;
42 
43  enum {
44  RowsAtCompileTime = SkewSymmetricVectorType::SizeAtCompileTime,
45  ColsAtCompileTime = SkewSymmetricVectorType::SizeAtCompileTime,
46  MaxRowsAtCompileTime = SkewSymmetricVectorType::MaxSizeAtCompileTime,
47  MaxColsAtCompileTime = SkewSymmetricVectorType::MaxSizeAtCompileTime,
50  };
51 
55 
58  inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
61  inline Derived& derived() { return *static_cast<Derived*>(this); }
62 
68  DenseMatrixType toDenseMatrix() const { return derived(); }
69 
72  inline Scalar determinant() const { return 0; }
73 
76  PlainObject transpose() const { return (-vector()).asSkewSymmetric(); }
77 
82  const SkewSymmetricVectorType& v = vector();
83  if (v.isZero()) {
84  return retVal;
85  }
86  const Scalar norm2 = v.squaredNorm();
87  const Scalar norm = numext::sqrt(norm2);
88  retVal += ((((1 - numext::cos(norm))/norm2)*derived())*derived()) + (numext::sin(norm)/norm)*derived().toDenseMatrix();
89  return retVal;
90  }
91 
94  inline const SkewSymmetricVectorType& vector() const { return derived().vector(); }
97  inline SkewSymmetricVectorType& vector() { return derived().vector(); }
98 
101  inline Index rows() const { return 3; }
104  inline Index cols() const { return 3; }
105 
107  template<typename MatrixDerived>
111  {
113  }
114 
116  template<typename MatrixDerived>
120  {
122  }
123 
124  template <typename OtherDerived>
126  SkewSymmetricVectorType, typename OtherDerived::SkewSymmetricVectorType, product)>;
127 
130  template <typename OtherDerived>
132  const SkewSymmetricBase<OtherDerived>& other) const {
133  return vector().cross(other.vector()).asSkewSymmetric();
134  }
135 
138 
141  inline SkewSymmetricScaleReturnType operator*(const Scalar& scalar) const {
142  return (vector() * scalar).asSkewSymmetric();
143  }
144 
147 
150  friend inline ScaleSkewSymmetricReturnType operator*(const Scalar& scalar, const SkewSymmetricBase& other) {
151  return (scalar * other.vector()).asSkewSymmetric();
152  }
153 
154  template <typename OtherDerived>
156  SkewSymmetricVectorType, typename OtherDerived::SkewSymmetricVectorType, sum)>;
157 
159  template <typename OtherDerived>
161  const SkewSymmetricBase<OtherDerived>& other) const {
162  return (vector() + other.vector()).asSkewSymmetric();
163  }
164 
165  template <typename OtherDerived>
167  SkewSymmetricVectorType, typename OtherDerived::SkewSymmetricVectorType, difference)>;
168 
170  template <typename OtherDerived>
172  const SkewSymmetricBase<OtherDerived>& other) const {
173  return (vector() - other.vector()).asSkewSymmetric();
174  }
175 };
176 
187 namespace internal {
188 template<typename Scalar_>
189 struct traits<SkewSymmetricMatrix3<Scalar_> >
190  : traits<Matrix<Scalar_,3,3,0,3,3> >
191 {
192  typedef Matrix<Scalar_,3,1,0,3,1> SkewSymmetricVectorType;
194  enum {
196  };
197 };
198 }
199 template<typename Scalar_>
201  : public SkewSymmetricBase<SkewSymmetricMatrix3<Scalar_> >
202 {
203  public:
204  #ifndef EIGEN_PARSED_BY_DOXYGEN
205  typedef typename internal::traits<SkewSymmetricMatrix3>::SkewSymmetricVectorType SkewSymmetricVectorType;
206  typedef const SkewSymmetricMatrix3& Nested;
207  typedef Scalar_ Scalar;
208  typedef typename internal::traits<SkewSymmetricMatrix3>::StorageKind StorageKind;
209  typedef typename internal::traits<SkewSymmetricMatrix3>::StorageIndex StorageIndex;
210  #endif
211 
212  protected:
213 
215 
216  public:
217 
220  inline const SkewSymmetricVectorType& vector() const { return m_vector; }
224 
228 
231  inline SkewSymmetricMatrix3(const Scalar& x, const Scalar& y, const Scalar& z) : m_vector(x,y,z) {}
232 
235  explicit inline SkewSymmetricMatrix3(SkewSymmetricVectorType&& vec) : m_vector(std::move(vec)) {}
236 
238  template<typename OtherDerived>
240  explicit inline SkewSymmetricMatrix3(const MatrixBase<OtherDerived>& other) : m_vector(other)
241  {}
242 
244  template<typename OtherDerived>
247 
248  #ifndef EIGEN_PARSED_BY_DOXYGEN
250  inline SkewSymmetricMatrix3(const SkewSymmetricMatrix3& other) : m_vector(other.vector()) {}
251  #endif
252 
254  template<typename OtherDerived>
257  {
258  m_vector = other.vector();
259  return *this;
260  }
261 
262  #ifndef EIGEN_PARSED_BY_DOXYGEN
268  {
269  m_vector = other.vector();
270  return *this;
271  }
272  #endif
273 
276 
279  static InitializeReturnType Zero() { return SkewSymmetricVectorType::Zero().asSkewSymmetric(); }
280 
283  inline void setZero() { m_vector.setZero(); }
284 };
285 
300 namespace internal {
301 template<typename SkewSymmetricVectorType_>
302 struct traits<SkewSymmetricWrapper<SkewSymmetricVectorType_> >
303 {
304  typedef SkewSymmetricVectorType_ SkewSymmetricVectorType;
305  typedef typename SkewSymmetricVectorType::Scalar Scalar;
306  typedef typename SkewSymmetricVectorType::StorageIndex StorageIndex;
307  typedef SkewSymmetricShape StorageKind;
308  typedef typename traits<SkewSymmetricVectorType>::XprKind XprKind;
309  enum {
310  RowsAtCompileTime = SkewSymmetricVectorType::SizeAtCompileTime,
311  ColsAtCompileTime = SkewSymmetricVectorType::SizeAtCompileTime,
312  MaxRowsAtCompileTime = SkewSymmetricVectorType::MaxSizeAtCompileTime,
313  MaxColsAtCompileTime = SkewSymmetricVectorType::MaxSizeAtCompileTime,
314  Flags = (traits<SkewSymmetricVectorType>::Flags & LvalueBit) | NoPreferredStorageOrderBit
315  };
316 };
317 }
318 
319 template<typename SkewSymmetricVectorType_>
321  : public SkewSymmetricBase<SkewSymmetricWrapper<SkewSymmetricVectorType_> >, internal::no_assignment_operator
322 {
323  public:
324  #ifndef EIGEN_PARSED_BY_DOXYGEN
325  typedef SkewSymmetricVectorType_ SkewSymmetricVectorType;
326  typedef SkewSymmetricWrapper Nested;
327  #endif
328 
331  explicit inline SkewSymmetricWrapper(SkewSymmetricVectorType& a_vector) : m_vector(a_vector) {}
332 
335  const SkewSymmetricVectorType& vector() const { return m_vector; }
336 
337  protected:
338  typename SkewSymmetricVectorType::Nested m_vector;
339 };
340 
347 template<typename Derived>
350 {
351  return SkewSymmetricWrapper<const Derived>(derived());
352 }
353 
357 template<typename Derived>
359 {
360  if(cols() != rows()) return false;
361  return (this->transpose() + *this).isZero(prec);
362 }
363 
366 template<typename Derived>
367 template<typename SkewDerived>
370 {
371  return Product<Derived, SkewDerived, LazyProduct>(derived(), skew.derived());
372 }
373 
374 namespace internal {
375 
376 template<> struct storage_kind_to_shape<SkewSymmetricShape> { typedef SkewSymmetricShape Shape; };
377 
378 struct SkewSymmetric2Dense {};
379 
380 template<> struct AssignmentKind<DenseShape,SkewSymmetricShape> { typedef SkewSymmetric2Dense Kind; };
381 
382 // SkewSymmetric matrix to Dense assignment
383 template< typename DstXprType, typename SrcXprType, typename Functor>
384 struct Assignment<DstXprType, SrcXprType, Functor, SkewSymmetric2Dense>
385 {
387  static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
388  {
389  if((dst.rows()!=3) || (dst.cols()!=3)) {
390  dst.resize(3, 3);
391  }
392  dst.diagonal().setZero();
393  const typename SrcXprType::SkewSymmetricVectorType v = src.vector();
394  dst(0, 1) = -v(2);
395  dst(1, 0) = v(2);
396  dst(0, 2) = v(1);
397  dst(2, 0) = -v(1);
398  dst(1, 2) = -v(0);
399  dst(2, 1) = v(0);
400  }
402  static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
403  { dst.vector() += src.vector(); }
404 
406  static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &/*func*/)
407  { dst.vector() -= src.vector(); }
408 };
409 
410 } // namespace internal
411 
412 } // end namespace Eigen
413 
414 #endif // EIGEN_SKEWSYMMETRICMATRIX3_H
Array< int, Dynamic, 1 > v
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_CWISE_BINARY_RETURN_TYPE(LHS, RHS, OPNAME)
Definition: Macros.h:1182
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(EXPR, SCALAR, OPNAME)
Definition: Macros.h:1203
#define EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(SCALAR, EXPR, OPNAME)
Definition: Macros.h:1207
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:68
internal::traits< Homogeneous< MatrixType, Direction_ > >::StorageKind StorageKind
Definition: DenseBase.h:50
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
const SkewSymmetricWrapper< const Derived > asSkewSymmetric() const
static const IdentityReturnType Identity()
bool isSkewSymmetric(const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
const Product< Derived, OtherDerived > operator*(const MatrixBase< OtherDerived > &other) const
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:77
Base class for skew symmetric matrices and expressions.
SkewSymmetricVectorType::RealScalar RealScalar
SkewSymmetricDifferenceReturnType< OtherDerived > operator-(const SkewSymmetricBase< OtherDerived > &other) const
SkewSymmetricVectorType & vector()
const Derived & derived() const
DenseMatrixType toDenseMatrix() const
Product< Derived, MatrixDerived, LazyProduct > operator*(const SkewSymmetricBase< MatrixDerived > &matrix) const
SkewSymmetricScaleReturnType operator*(const Scalar &scalar) const
EIGEN_CONSTEXPR Index cols() const
const SkewSymmetricVectorType & vector() const
Product< Derived, MatrixDerived, LazyProduct > operator*(const MatrixBase< MatrixDerived > &matrix) const
internal::traits< Derived >::StorageIndex StorageIndex
internal::traits< Derived >::SkewSymmetricVectorType SkewSymmetricVectorType
EIGEN_CONSTEXPR Index rows() const
DenseMatrixType exponential() const
friend ScaleSkewSymmetricReturnType operator*(const Scalar &scalar, const SkewSymmetricBase &other)
EIGEN_CONSTEXPR Scalar determinant() const
SkewSymmetricVectorType::Scalar Scalar
internal::traits< Derived >::StorageKind StorageKind
SkewSymmetricSumReturnType< OtherDerived > operator+(const SkewSymmetricBase< OtherDerived > &other) const
SkewSymmetricMatrix3< Scalar > PlainObject
SkewSymmetricProductReturnType< OtherDerived > wedge(const SkewSymmetricBase< OtherDerived > &other) const
PlainObject transpose() const
Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, 0, MaxRowsAtCompileTime, MaxColsAtCompileTime > DenseMatrixType
Represents a 3x3 skew symmetric matrix with its storage.
SkewSymmetricWrapper< const CwiseNullaryOp< internal::scalar_constant_op< Scalar >, SkewSymmetricVectorType > > InitializeReturnType
SkewSymmetricMatrix3(SkewSymmetricVectorType &&vec)
Constructs a SkewSymmetricMatrix3 from an r-value vector type.
SkewSymmetricMatrix3 & operator=(const SkewSymmetricBase< OtherDerived > &other)
const SkewSymmetricVectorType & vector() const
SkewSymmetricVectorType m_vector
SkewSymmetricMatrix3(const Scalar &x, const Scalar &y, const Scalar &z)
SkewSymmetricVectorType & vector()
static InitializeReturnType Zero()
SkewSymmetricMatrix3(const MatrixBase< OtherDerived > &other)
SkewSymmetricMatrix3(const SkewSymmetricBase< OtherDerived > &other)
Expression of a skew symmetric matrix.
SkewSymmetricVectorType::Nested m_vector
SkewSymmetricWrapper(SkewSymmetricVectorType &a_vector)
const SkewSymmetricVectorType & vector() const
const unsigned int NoPreferredStorageOrderBit
Definition: Constants.h:180
const unsigned int LvalueBit
Definition: Constants.h:146
const Scalar & y
EIGEN_ALWAYS_INLINE T sin(const T &x)
EIGEN_ALWAYS_INLINE float sqrt(const float &x)
EIGEN_ALWAYS_INLINE T cos(const T &x)
: InteropHeaders
Definition: Core:139
const unsigned int NestByRefBit
Definition: Constants.h:171
Definition: BFloat16.h:222
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41