Go to the documentation of this file.
13 #include <Eigen/src/Geometry/OrthoMethods.h>
14 #include <Eigen/src/Geometry/Quaternion.h>
15 #include <Eigen/src/Geometry/RotationBase.h>
18 template <
class Scalar_,
int Options = 0>
27 template <
class Scalar_,
int Options>
28 struct traits<
Sophus::SO3<Scalar_, Options>> {
33 template <
class Scalar_,
int Options>
34 struct traits<Map<
Sophus::SO3<Scalar_>, Options>>
35 : traits<Sophus::SO3<Scalar_, Options>> {
40 template <
class Scalar_,
int Options>
41 struct traits<Map<
Sophus::SO3<Scalar_> const, Options>>
42 : traits<Sophus::SO3<Scalar_, Options> const> {
73 template <
class Derived>
76 using Scalar =
typename Eigen::internal::traits<Derived>::Scalar;
78 typename Eigen::internal::traits<Derived>::QuaternionType;
81 static int constexpr
DoF = 3;
85 static int constexpr
N = 3;
94 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
104 template <
typename OtherDerived>
105 using ReturnScalar =
typename Eigen::ScalarBinaryOpTraits<
106 Scalar,
typename OtherDerived::Scalar>::ReturnType;
108 template <
typename OtherDerived>
111 template <
typename Po
intDerived>
114 template <
typename HPo
intDerived>
129 template <
class S = Scalar>
138 template <
class S = Scalar>
152 template <
class S = Scalar>
161 template <
class NewScalarType>
250 Scalar two_atan_nbyw_by_n;
263 "Quaternion (%) should be normalized!",
267 Scalar(2) / w -
Scalar(2) * (squared_n) / (w * squared_w);
268 J.theta =
Scalar(2) * squared_n / w;
270 Scalar n = sqrt(squared_n);
278 two_atan_nbyw_by_n =
Scalar(2) * atan(n / w) / n;
280 J.theta = two_atan_nbyw_by_n * n;
295 "Quaternion (%) should not be close to zero!",
315 template <
class OtherDerived>
323 template <
typename OtherDerived>
326 using QuaternionProductType =
329 const typename OtherDerived::QuaternionType& b = other.
unit_quaternion();
334 a.w() * b.w() - a.x() * b.x() - a.y() * b.y() - a.z() * b.z(),
335 a.w() * b.x() + a.x() * b.w() + a.y() * b.z() - a.z() * b.y(),
336 a.w() * b.y() + a.y() * b.w() + a.z() * b.x() - a.x() * b.z(),
337 a.w() * b.z() + a.z() * b.w() + a.x() * b.y() - a.y() * b.x()));
354 template <
typename PointDerived,
355 typename =
typename std::enable_if<
358 Eigen::MatrixBase<PointDerived>
const& p)
const {
365 return p + q.w() * uv + q.vec().cross(uv);
369 template <
typename HPointDerived,
370 typename =
typename std::enable_if<
373 Eigen::MatrixBase<HPointDerived>
const& p)
const {
374 const auto rp = *
this * p.template head<3>();
386 return Line((*
this) * l.origin(), (*
this) * l.direction());
392 template <
typename OtherDerived,
393 typename =
typename std::enable_if<
394 std::is_same<Scalar, ReturnScalar<OtherDerived>>::value>::type>
396 *
static_cast<Derived*
>(
this) = *
this * other;
425 template <
class Scalar_,
int Options>
426 class SO3 :
public SO3Base<SO3<Scalar_, Options>> {
444 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
457 template <
class OtherDerived>
481 std::is_same<
typename Eigen::QuaternionBase<D>::Scalar,
Scalar>::value,
482 "Input must be of same scalar type");
500 Scalar const c0 = omega[0] * omega[0];
501 Scalar const c1 = omega[1] * omega[1];
502 Scalar const c2 = omega[2] * omega[2];
536 J(3, 0) = -
c20 * omega[0];
537 J(3, 1) = -
c20 * omega[1];
538 J(3, 2) = -
c20 * omega[2];
587 Scalar theta_sq = omega.squaredNorm();
594 Scalar theta_po4 = theta_sq * theta_sq;
595 imag_factor =
Scalar(0.5) -
Scalar(1.0 / 48.0) * theta_sq +
596 Scalar(1.0 / 3840.0) * theta_po4;
597 real_factor =
Scalar(1) -
Scalar(1.0 / 8.0) * theta_sq +
598 Scalar(1.0 / 384.0) * theta_po4;
600 *theta = sqrt(theta_sq);
602 Scalar sin_half_theta = sin(half_theta);
603 imag_factor = sin_half_theta / (*theta);
604 real_factor = cos(half_theta);
608 q.unit_quaternion_nonconst() =
610 imag_factor * omega.y(), imag_factor * omega.z());
613 "SO3::exp failed! omega: %, real: %, img: %",
614 omega.transpose(), real_factor, imag_factor);
620 template <
class S = Scalar>
647 SOPHUS_ENSURE(i >= 0 && i <= 2,
"i should be in range [0,2].");
672 Scalar(0), -omega(2), omega(1),
673 omega(2),
Scalar(0), -omega(0),
674 -omega(1), omega(0),
Scalar(0);
694 return omega1.cross(omega2);
717 template <
class UniformRandomBitGenerator>
720 "generator must meet the UniformRandomBitGenerator concept");
723 std::normal_distribution<Scalar> normal(0, 1);
750 return Tangent(Omega(2, 1), Omega(0, 2), Omega(1, 0));
770 template <
class Scalar_,
int Options>
787 EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Map);
790 using Base::operator*=;
791 using Base::operator*;
799 return unit_quaternion_;
805 SOPHUS_FUNC Map<Eigen::Quaternion<Scalar>, Options>&
807 return unit_quaternion_;
817 template <
class Scalar_,
int Options>
818 class Map<
Sophus::SO3<Scalar_> const, Options>
829 using Base::operator*=;
830 using Base::operator*;
836 SOPHUS_FUNC Map<Eigen::Quaternion<Scalar>
const, Options>
const&
838 return unit_quaternion_;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Tangent tangent
SO2 using default storage; derived from SO2Base.
SOPHUS_FUNC Map(Scalar const *coeffs)
static SOPHUS_FUNC SO3 rotX(Scalar const &x)
SOPHUS_FUNC SO3< Scalar > inverse() const
SOPHUS_FUNC Map< Eigen::Quaternion< Scalar > const, Options > const & unit_quaternion() const
static constexpr int num_parameters
typename Eigen::internal::traits< Map< Sophus::SO3< Scalar_ > const, Options > >::Scalar Scalar
SO3 using default storage; derived from SO3Base.
SOPHUS_FUNC QuaternionMember & unit_quaternion_nonconst()
SOPHUS_FUNC Map< Eigen::Quaternion< Scalar >, Options > & unit_quaternion_nonconst()
Map< Eigen::Quaternion< Scalar >, Options > unit_quaternion_
static SOPHUS_FUNC Tangent vee(Transformation const &Omega)
SOPHUS_FUNC Scalar const * data() const
typename Base::Transformation Transformation
static SOPHUS_FUNC SO3< Scalar > exp(Tangent const &omega)
Vector4< ReturnScalar< HPointDerived > > HomogeneousPointProduct
Vector< Scalar, 3, Options > Vector3
static constexpr int N
Group transformations are 3x3 matrices.
typename std::enable_if< B, T >::type enable_if_t
Matrix< Scalar, 2, 2 > Matrix2
Vector< Scalar, DoF > Tangent
#define SOPHUS_ENSURE(expr,...)
typename Base::Tangent Tangent
SOPHUS_FUNC HomogeneousPointProduct< HPointDerived > operator*(Eigen::MatrixBase< HPointDerived > const &p) const
Group action on homogeneous 3-points. See above for more details.
SOPHUS_FUNC Matrix< Scalar, num_parameters, DoF > Dx_this_mul_exp_x_at_0() const
const Map< Eigen::Quaternion< Scalar > const, Options > unit_quaternion_
Matrix< Scalar, N, N > Transformation
typename Base::Adjoint Adjoint
ParametrizedLine< Scalar, 3, Options > ParametrizedLine3
SOPHUS_FUNC SO3(Transformation const &R)
SOPHUS_FUNC Tangent log() const
typename Eigen::internal::traits< Map< Sophus::SO3< Scalar_ > const, Options > >::QuaternionType QuaternionType
typename Base::Transformation Transformation
SOPHUS_FUNC TangentAndTheta logAndTheta() const
typename Base::Tangent Tangent
typename Base::Adjoint Adjoint
SOPHUS_FUNC SO3Base< Derived > & operator*=(SO3Base< OtherDerived > const &other)
Eigen::Matrix< Scalar, M, N > Matrix
SOPHUS_FUNC SO3Product< OtherDerived > operator*(SO3Base< OtherDerived > const &other) const
static SOPHUS_FUNC Transformation hat(Tangent const &omega)
SOPHUS_FUNC bool isOrthogonal(Eigen::MatrixBase< D > const &R)
SOPHUS_FUNC Adjoint Adj() const
Adjoint transformation.
static SOPHUS_FUNC Sophus::Matrix< Scalar, num_parameters, DoF > Dx_exp_x(Tangent const &omega)
static constexpr int num_parameters
Number of internal parameters used (quaternion is a 4-tuple).
auto transpose(T const &p) -> decltype(details::Transpose< T >::impl(T()))
SOPHUS_FUNC SO3Base & operator=(SO3Base const &other)=default
SOPHUS_FUNC Scalar * data()
static SOPHUS_FUNC SO3 rotY(Scalar const &y)
Vector4< Scalar > HomogeneousPoint
SOPHUS_FUNC enable_if_t< std::is_floating_point< typename D::Scalar >::value, Matrix< typename D::Scalar, D::RowsAtCompileTime, D::RowsAtCompileTime > > makeRotationMatrix(Eigen::MatrixBase< D > const &R)
static SO3 sampleUniform(UniformRandomBitGenerator &generator)
ParametrizedLine3< Scalar > Line
static SOPHUS_FUNC enable_if_t< std::is_floating_point< S >::value, SO3 > fitToSO3(Transformation const &R)
static SOPHUS_FUNC Scalar pi()
typename Eigen::ScalarBinaryOpTraits< Scalar, typename OtherDerived::Scalar >::ReturnType ReturnScalar
SOPHUS_FUNC SO3Base< Derived > & operator=(SO3Base< OtherDerived > const &other)
static SOPHUS_FUNC SO3 rotZ(Scalar const &z)
SOPHUS_FUNC void normalize()
SOPHUS_FUNC SO3(SO3Base< OtherDerived > const &other)
Matrix< Scalar, 3, 3 > Matrix3
typename Base::Point Point
typename Base::HomogeneousPoint HomogeneousPoint
Vector< Scalar, 4 > Vector4
SOPHUS_FUNC QuaternionType const & unit_quaternion() const
static SOPHUS_FUNC Transformation Dxi_exp_x_matrix_at_0(int i)
typename Base::HomogeneousPoint HomogeneousPoint
Map< Eigen::Quaternion< Scalar > const, Options > QuaternionType
Vector3< ReturnScalar< PointDerived > > PointProduct
static SOPHUS_FUNC Transformation generator(int i)
typename Base::Point Point
SOPHUS_FUNC enable_if_t< std::is_floating_point< S >::value, S > angleY() const
Eigen::Quaternion< Scalar, Options > QuaternionMember
Eigen::Matrix< Scalar, M, 1, Options > Vector
SOPHUS_FUNC Map< Eigen::Quaternion< Scalar >, Options > const & unit_quaternion() const
static SOPHUS_FUNC Tangent lieBracket(Tangent const &omega1, Tangent const &omega2)
SOPHUS_FUNC PointProduct< PointDerived > operator*(Eigen::MatrixBase< PointDerived > const &p) const
SOPHUS_FUNC void setQuaternion(Eigen::Quaternion< Scalar > const &quaternion)
SOPHUS_FUNC QuaternionType & unit_quaternion_nonconst()
EIGEN_MAKE_ALIGNED_OPERATOR_NEW SOPHUS_FUNC SO3()
SOPHUS_FUNC Transformation matrix() const
SOPHUS_FUNC SO3< NewScalarType > cast() const
static SOPHUS_FUNC SO3< Scalar > expAndTheta(Tangent const &omega, Scalar *theta)
Eigen::Quaternion< Scalar, Options > QuaternionType
SOPHUS_FUNC SO3(Eigen::QuaternionBase< D > const &quat)
SOPHUS_FUNC Sophus::Vector< Scalar, num_parameters > params() const
SOPHUS_FUNC QuaternionMember const & unit_quaternion() const
SOPHUS_FUNC enable_if_t< std::is_floating_point< S >::value, S > angleX() const
SOPHUS_FUNC Line operator*(Line const &l) const
SOPHUS_FUNC enable_if_t< std::is_floating_point< S >::value, S > angleZ() const
static SOPHUS_FUNC Sophus::Matrix< Scalar, num_parameters, DoF > Dx_exp_x_at_0()
static constexpr int DoF
Degrees of freedom of group, number of dimensions in tangent space.
QuaternionMember unit_quaternion_
Matrix< Scalar, DoF, DoF > Adjoint
sophus
Author(s): Hauke Strasdat
autogenerated on Wed Mar 2 2022 01:01:48