11#ifndef EIGEN_ANGLEAXIS_H
12#define EIGEN_ANGLEAXIS_H
15#include "./InternalHeaderCheck.h"
46template <
typename Scalar_>
47struct traits<AngleAxis<Scalar_> > {
48 using Scalar = Scalar_;
52template <
typename Scalar_>
57 using Base::operator*;
78 template <
typename Derived>
84 template <
typename QuatDerived>
89 template <
typename Derived>
100 EIGEN_DEVICE_FUNC
const Vector3&
axis()
const {
return m_axis; }
105 EIGEN_DEVICE_FUNC Vector3&
axis() {
return m_axis; }
109 return QuaternionType(*
this) * QuaternionType(other);
113 EIGEN_DEVICE_FUNC
inline QuaternionType
operator*(
const QuaternionType& other)
const {
114 return QuaternionType(*
this) * other;
118 friend EIGEN_DEVICE_FUNC
inline QuaternionType
operator*(
const QuaternionType& a,
const AngleAxis& b) {
119 return a * QuaternionType(b);
125 template <
class QuatDerived>
127 template <
typename Derived>
130 template <
typename Derived>
136 template <
typename OtherVectorType>
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Vector3
_transformVector(
const OtherVectorType& v)
const {
138 EIGEN_INTERNAL_ASSERT_SAME_SIZE(v, m_axis);
142 const Scalar c = numext::cos(m_angle);
143 const Scalar s = numext::sin(m_angle);
144 return v3 * c + m_axis.cross(v3) * s + m_axis * (m_axis.dot(v3) * (
Scalar(1) - c));
152 template <
typename NewScalarType>
153 EIGEN_DEVICE_FUNC
inline typename internal::cast_return_type<AngleAxis, AngleAxis<NewScalarType> >::type
cast()
155 return typename internal::cast_return_type<AngleAxis, AngleAxis<NewScalarType> >::type(*
this);
159 template <
typename OtherScalarType>
171 EIGEN_DEVICE_FUNC
bool isApprox(
const AngleAxis& other,
const typename NumTraits<Scalar>::Real& prec =
172 NumTraits<Scalar>::dummy_precision())
const {
173 return m_axis.isApprox(other.m_axis, prec) && internal::isApprox(m_angle, other.m_angle, prec);
190template <
typename Scalar>
191template <
typename QuatDerived>
194 if (n < NumTraits<Scalar>::epsilon()) n = q.
vec().stableNorm();
197 m_angle =
Scalar(2) * numext::atan2(n, numext::abs(q.
w()));
199 m_axis = q.
vec() / n;
209template <
typename Scalar>
210template <
typename Derived>
213 if (mat.size() == 4) {
214 return *
this = QuaternionType(mat);
216 return fromRotationMatrix(mat);
224template <
typename Scalar>
225template <
typename Derived>
228 (std::is_same<Scalar, typename Derived::Scalar>::value),
229 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
232 EIGEN_INTERNAL_SHAPE_ASSERT((internal::fixed_dimensions<Derived, 3, 3>::Proven), mat.cols() == 3 && mat.rows() == 3);
239 internal::quaternionbase_assign_impl<Derived, 3, 3>::template run<false>(q, mat.derived());
245template <
typename Scalar>
248 Vector3 sin_axis = numext::sin(m_angle) * m_axis;
249 Scalar c = numext::cos(m_angle);
250 Vector3 cos1_axis = (
Scalar(1) - c) * m_axis;
253 tmp = cos1_axis.x() * m_axis.y();
254 res.
coeffRef(0, 1) = tmp - sin_axis.z();
255 res.
coeffRef(1, 0) = tmp + sin_axis.z();
257 tmp = cos1_axis.x() * m_axis.z();
258 res.
coeffRef(0, 2) = tmp + sin_axis.y();
259 res.
coeffRef(2, 0) = tmp - sin_axis.y();
261 tmp = cos1_axis.y() * m_axis.z();
262 res.
coeffRef(1, 2) = tmp - sin_axis.x();
263 res.
coeffRef(2, 1) = tmp + sin_axis.x();
265 res.diagonal() = cos1_axis.cwiseProduct(m_axis).array() + c;
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Definition AngleAxis.h:53
QuaternionType operator*(const QuaternionType &other) const
Definition AngleAxis.h:113
AngleAxis(const AngleAxis< OtherScalarType > &other)
Definition AngleAxis.h:160
QuaternionType operator*(const AngleAxis &other) const
Definition AngleAxis.h:108
Scalar & angle()
Definition AngleAxis.h:97
Vector3 & axis()
Definition AngleAxis.h:105
AngleAxis(const QuaternionBase< QuatDerived > &q)
Definition AngleAxis.h:85
internal::cast_return_type< AngleAxis, AngleAxis< NewScalarType > >::type cast() const
Definition AngleAxis.h:153
Vector3 _transformVector(const OtherVectorType &v) const
Definition AngleAxis.h:137
AngleAxis(const Scalar &angle, const MatrixBase< Derived > &axis)
Definition AngleAxis.h:79
Scalar_ Scalar
Definition AngleAxis.h:61
AngleAxis(const MatrixBase< Derived > &m)
Definition AngleAxis.h:90
AngleAxis inverse() const
Definition AngleAxis.h:123
const Vector3 & axis() const
Definition AngleAxis.h:100
AngleAxis()
Definition AngleAxis.h:72
bool isApprox(const AngleAxis &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition AngleAxis.h:171
friend QuaternionType operator*(const QuaternionType &a, const AngleAxis &b)
Definition AngleAxis.h:118
Matrix3 toRotationMatrix(void) const
Definition AngleAxis.h:246
Scalar angle() const
Definition AngleAxis.h:95
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
constexpr Scalar & coeffRef(Index rowId, Index colId)
Definition PlainObjectBase.h:205
Base class for quaternion expressions.
Definition Quaternion.h:36
const VectorBlock< const Coefficients, 3 > vec() const
Definition Quaternion.h:78
constexpr CoeffReturnType w() const
Definition Quaternion.h:66
The quaternion class used to represent 3D orientations and rotations.
Definition Quaternion.h:300
Common base class for compact rotation representations.
Definition RotationBase.h:33
AngleAxis< double > AngleAxisd
Definition AngleAxis.h:182
AngleAxis< float > AngleAxisf
Definition AngleAxis.h:179