2008-06-15 17:22:41 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-06-15 17:22:41 +00:00
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-06-15 17:22:41 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-06-15 17:22:41 +00:00
|
|
|
|
2008-08-30 21:36:04 +00:00
|
|
|
#ifndef EIGEN_ROTATIONBASE_H
|
|
|
|
|
#define EIGEN_ROTATIONBASE_H
|
2008-06-15 17:22:41 +00:00
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
namespace Eigen {
|
2012-04-15 11:06:28 +01:00
|
|
|
|
2009-07-31 10:04:34 +02:00
|
|
|
// forward declaration
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename RotationDerived, typename MatrixType, bool IsVector = MatrixType::IsVectorAtCompileTime>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct rotation_base_generic_product_selector;
|
|
|
|
|
}
|
2008-06-15 17:22:41 +00:00
|
|
|
|
2008-08-30 20:11:04 +00:00
|
|
|
/** \class RotationBase
|
2023-11-29 11:12:48 +00:00
|
|
|
*
|
|
|
|
|
* \brief Common base class for compact rotation representations
|
|
|
|
|
*
|
|
|
|
|
* \tparam Derived is the derived type, i.e., a rotation type
|
|
|
|
|
* \tparam Dim_ the dimension of the space
|
|
|
|
|
*/
|
|
|
|
|
template <typename Derived, int Dim_>
|
|
|
|
|
class RotationBase {
|
|
|
|
|
public:
|
|
|
|
|
enum { Dim = Dim_ };
|
|
|
|
|
/** the scalar type of the coefficients */
|
|
|
|
|
typedef typename internal::traits<Derived>::Scalar Scalar;
|
|
|
|
|
|
|
|
|
|
/** corresponding linear transformation matrix type */
|
|
|
|
|
typedef Matrix<Scalar, Dim, Dim> RotationMatrixType;
|
|
|
|
|
typedef Matrix<Scalar, Dim, 1> VectorType;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
|
|
|
|
EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast<Derived*>(this); }
|
|
|
|
|
|
|
|
|
|
/** \returns an equivalent rotation matrix */
|
|
|
|
|
EIGEN_DEVICE_FUNC inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); }
|
|
|
|
|
|
|
|
|
|
/** \returns an equivalent rotation matrix
|
|
|
|
|
* This function is added to be conform with the Transform class' naming scheme.
|
|
|
|
|
*/
|
|
|
|
|
EIGEN_DEVICE_FUNC inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); }
|
|
|
|
|
|
|
|
|
|
/** \returns the inverse rotation */
|
|
|
|
|
EIGEN_DEVICE_FUNC inline Derived inverse() const { return derived().inverse(); }
|
|
|
|
|
|
|
|
|
|
/** \returns the concatenation of the rotation \c *this with a translation \a t */
|
|
|
|
|
EIGEN_DEVICE_FUNC inline Transform<Scalar, Dim, Isometry> operator*(const Translation<Scalar, Dim>& t) const {
|
|
|
|
|
return Transform<Scalar, Dim, Isometry>(*this) * t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns the concatenation of the rotation \c *this with a uniform scaling \a s */
|
|
|
|
|
EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const UniformScaling<Scalar>& s) const {
|
|
|
|
|
return toRotationMatrix() * s.factor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns the concatenation of the rotation \c *this with a generic expression \a e
|
|
|
|
|
* \a e can be:
|
|
|
|
|
* - a DimxDim linear transformation matrix
|
|
|
|
|
* - a DimxDim diagonal matrix (axis aligned scaling)
|
|
|
|
|
* - a vector of size Dim
|
|
|
|
|
*/
|
|
|
|
|
template <typename OtherDerived>
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
|
|
|
|
typename internal::rotation_base_generic_product_selector<Derived, OtherDerived,
|
|
|
|
|
OtherDerived::IsVectorAtCompileTime>::ReturnType
|
|
|
|
|
operator*(const EigenBase<OtherDerived>& e) const {
|
|
|
|
|
return internal::rotation_base_generic_product_selector<Derived, OtherDerived>::run(derived(), e.derived());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns the concatenation of a linear transformation \a l with the rotation \a r */
|
|
|
|
|
template <typename OtherDerived>
|
|
|
|
|
friend EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const EigenBase<OtherDerived>& l, const Derived& r) {
|
|
|
|
|
return l.derived() * r.toRotationMatrix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns the concatenation of a scaling \a l with the rotation \a r */
|
|
|
|
|
EIGEN_DEVICE_FUNC friend inline Transform<Scalar, Dim, Affine> operator*(const DiagonalMatrix<Scalar, Dim>& l,
|
|
|
|
|
const Derived& r) {
|
|
|
|
|
Transform<Scalar, Dim, Affine> res(r);
|
|
|
|
|
res.linear().applyOnTheLeft(l);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \returns the concatenation of the rotation \c *this with a transformation \a t */
|
|
|
|
|
template <int Mode, int Options>
|
|
|
|
|
EIGEN_DEVICE_FUNC inline Transform<Scalar, Dim, Mode> operator*(
|
|
|
|
|
const Transform<Scalar, Dim, Mode, Options>& t) const {
|
|
|
|
|
return toRotationMatrix() * t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename OtherVectorType>
|
|
|
|
|
EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const {
|
|
|
|
|
return toRotationMatrix() * v;
|
|
|
|
|
}
|
2008-06-15 17:22:41 +00:00
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
2009-07-31 10:04:34 +02:00
|
|
|
// implementation of the generic product rotation * matrix
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename RotationDerived, typename MatrixType>
|
|
|
|
|
struct rotation_base_generic_product_selector<RotationDerived, MatrixType, false> {
|
2009-07-31 10:04:34 +02:00
|
|
|
enum { Dim = RotationDerived::Dim };
|
2023-11-29 11:12:48 +00:00
|
|
|
typedef Matrix<typename RotationDerived::Scalar, Dim, Dim> ReturnType;
|
|
|
|
|
EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m) {
|
|
|
|
|
return r.toRotationMatrix() * m;
|
|
|
|
|
}
|
2009-07-31 10:04:34 +02:00
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename RotationDerived, typename Scalar, int Dim, int MaxDim>
|
|
|
|
|
struct rotation_base_generic_product_selector<RotationDerived, DiagonalMatrix<Scalar, Dim, MaxDim>, false> {
|
|
|
|
|
typedef Transform<Scalar, Dim, Affine> ReturnType;
|
|
|
|
|
EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r,
|
|
|
|
|
const DiagonalMatrix<Scalar, Dim, MaxDim>& m) {
|
2010-08-19 19:25:35 +02:00
|
|
|
ReturnType res(r);
|
|
|
|
|
res.linear() *= m;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename RotationDerived, typename OtherVectorType>
|
|
|
|
|
struct rotation_base_generic_product_selector<RotationDerived, OtherVectorType, true> {
|
2009-07-31 10:04:34 +02:00
|
|
|
enum { Dim = RotationDerived::Dim };
|
2023-11-29 11:12:48 +00:00
|
|
|
typedef Matrix<typename RotationDerived::Scalar, Dim, 1> ReturnType;
|
|
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v) {
|
2009-07-31 10:04:34 +02:00
|
|
|
return r._transformVector(v);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
} // end namespace internal
|
2010-10-25 10:15:22 -04:00
|
|
|
|
2008-08-30 21:36:04 +00:00
|
|
|
/** \geometry_module
|
2023-11-29 11:12:48 +00:00
|
|
|
*
|
|
|
|
|
* \brief Constructs a Dim x Dim rotation matrix from the rotation \a r
|
|
|
|
|
*/
|
|
|
|
|
template <typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
|
|
|
|
|
template <typename OtherDerived>
|
|
|
|
|
EIGEN_DEVICE_FUNC Matrix<Scalar_, Rows_, Cols_, Storage_, MaxRows_, MaxCols_>::Matrix(
|
|
|
|
|
const RotationBase<OtherDerived, ColsAtCompileTime>& r) {
|
|
|
|
|
EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix, int(OtherDerived::Dim), int(OtherDerived::Dim))
|
2008-08-30 21:36:04 +00:00
|
|
|
*this = r.toRotationMatrix();
|
2008-06-15 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-30 21:36:04 +00:00
|
|
|
/** \geometry_module
|
2023-11-29 11:12:48 +00:00
|
|
|
*
|
|
|
|
|
* \brief Set a Dim x Dim rotation matrix from the rotation \a r
|
|
|
|
|
*/
|
|
|
|
|
template <typename Scalar_, int Rows_, int Cols_, int Storage_, int MaxRows_, int MaxCols_>
|
|
|
|
|
template <typename OtherDerived>
|
2022-01-10 20:53:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC Matrix<Scalar_, Rows_, Cols_, Storage_, MaxRows_, MaxCols_>&
|
2023-11-29 11:12:48 +00:00
|
|
|
Matrix<Scalar_, Rows_, Cols_, Storage_, MaxRows_, MaxCols_>::operator=(
|
|
|
|
|
const RotationBase<OtherDerived, ColsAtCompileTime>& r) {
|
|
|
|
|
EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix, int(OtherDerived::Dim), int(OtherDerived::Dim))
|
2008-08-30 21:36:04 +00:00
|
|
|
return *this = r.toRotationMatrix();
|
2008-06-15 17:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
2008-08-30 20:11:04 +00:00
|
|
|
/** \internal
|
2023-11-29 11:12:48 +00:00
|
|
|
*
|
|
|
|
|
* Helper function to return an arbitrary rotation object to a rotation matrix.
|
|
|
|
|
*
|
|
|
|
|
* \tparam Scalar the numeric type of the matrix coefficients
|
|
|
|
|
* \tparam Dim the dimension of the current space
|
|
|
|
|
*
|
|
|
|
|
* It returns a Dim x Dim fixed size matrix.
|
|
|
|
|
*
|
|
|
|
|
* Default specializations are provided for:
|
|
|
|
|
* - any scalar type (2D),
|
|
|
|
|
* - any matrix expression,
|
|
|
|
|
* - any type based on RotationBase (e.g., Quaternion, AngleAxis, Rotation2D)
|
|
|
|
|
*
|
|
|
|
|
* Currently toRotationMatrix is only used by Transform.
|
|
|
|
|
*
|
|
|
|
|
* \sa class Transform, class Rotation2D, class Quaternion, class AngleAxis
|
|
|
|
|
*/
|
|
|
|
|
template <typename Scalar, int Dim>
|
|
|
|
|
EIGEN_DEVICE_FUNC static inline Matrix<Scalar, 2, 2> toRotationMatrix(const Scalar& s) {
|
|
|
|
|
EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
|
2008-08-30 20:11:04 +00:00
|
|
|
return Rotation2D<Scalar>(s).toRotationMatrix();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename Scalar, int Dim, typename OtherDerived>
|
|
|
|
|
EIGEN_DEVICE_FUNC static inline Matrix<Scalar, Dim, Dim> toRotationMatrix(const RotationBase<OtherDerived, Dim>& r) {
|
2008-08-30 20:11:04 +00:00
|
|
|
return r.toRotationMatrix();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
template <typename Scalar, int Dim, typename OtherDerived>
|
|
|
|
|
EIGEN_DEVICE_FUNC static inline const MatrixBase<OtherDerived>& toRotationMatrix(const MatrixBase<OtherDerived>& mat) {
|
|
|
|
|
EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime == Dim && OtherDerived::ColsAtCompileTime == Dim,
|
|
|
|
|
YOU_MADE_A_PROGRAMMING_MISTAKE)
|
2008-08-30 20:11:04 +00:00
|
|
|
return mat;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
} // end namespace internal
|
2010-10-25 10:15:22 -04:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
} // end namespace Eigen
|
2012-04-15 11:06:28 +01:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
#endif // EIGEN_ROTATIONBASE_H
|