24 #include <gtsam/config.h>
27 #ifndef ROT3_DEFAULT_COORDINATES_MODE
28 #ifdef GTSAM_USE_QUATERNIONS
30 #define ROT3_DEFAULT_COORDINATES_MODE Rot3::EXPMAP
33 #ifndef GTSAM_ROT3_EXPMAP
35 #define ROT3_DEFAULT_COORDINATES_MODE Rot3::CAYLEY
37 #define ROT3_DEFAULT_COORDINATES_MODE Rot3::EXPMAP
42 #include <gtsam/base/DerivedValue.h>
45 #include <gtsam/geometry/Unit3.h>
52 typedef Eigen::Quaternion<double, Eigen::DontAlign>
Quaternion;
63 static const size_t dimension = 3;
66 #ifdef GTSAM_USE_QUATERNIONS
90 Rot3(
double R11,
double R12,
double R13,
91 double R21,
double R22,
double R23,
92 double R31,
double R32,
double R33);
95 Rot3(
const Matrix3& R);
98 Rot3(
const Matrix& R);
107 static Rot3 Random(boost::mt19937 & rng);
115 static Rot3 Rx(
double t);
118 static Rot3 Ry(
double t);
121 static Rot3 Rz(
double t);
124 static Rot3 RzRyRx(
double x,
double y,
double z);
128 assert(xyz.size() == 3);
129 return RzRyRx(xyz(0), xyz(1), xyz(2));
139 static Rot3 roll (
double t) {
return Rx(t); }
150 static Rot3 ypr (
double y,
double p,
double r) {
return RzRyRx(r,p,y);}
164 static Rot3 rodriguez(
const Vector& w,
double theta);
172 static Rot3 rodriguez(
const Point3& w,
double theta);
180 static Rot3 rodriguez(
const Unit3& w,
double theta);
187 static Rot3 rodriguez(
const Vector& v);
197 {
return rodriguez((Vector(3) << wx, wy, wz));}
204 void print(
const std::string& s=
"R")
const;
207 bool equals(
const Rot3& p,
double tol = 1e-9)
const;
219 Rot3 inverse(boost::optional<Matrix&> H1=boost::none)
const;
223 boost::optional<Matrix&> H1=boost::none, boost::optional<Matrix&> H2=boost::none)
const;
235 return cRb * (*this) * cRb.
inverse();
242 boost::optional<Matrix&> H1=boost::none,
243 boost::optional<Matrix&> H2=boost::none)
const;
250 static size_t Dim() {
return dimension; }
253 size_t dim()
const {
return dimension; }
266 #ifndef GTSAM_USE_QUATERNIONS
272 #ifndef GTSAM_USE_QUATERNIONS
273 Rot3 retractCayley(
const Vector& omega)
const;
293 else return rodriguez(v);
299 static Vector3 Logmap(
const Rot3& R);
302 static Matrix3 dexpL(
const Vector3& v);
305 static Matrix3 dexpInvL(
const Vector3& v);
311 static Matrix3 rightJacobianExpMapSO3(
const Vector3& x);
316 static Matrix3 rightJacobianExpMapSO3inverse(
const Vector3& x);
325 Point3 rotate(
const Point3& p, boost::optional<Matrix&> H1 = boost::none,
326 boost::optional<Matrix&> H2 = boost::none)
const;
334 Point3 unrotate(
const Point3& p, boost::optional<Matrix&> H1 = boost::none,
335 boost::optional<Matrix&> H2 = boost::none)
const;
342 Unit3 rotate(
const Unit3& p, boost::optional<Matrix&> HR = boost::none,
343 boost::optional<Matrix&> Hp = boost::none)
const;
346 Unit3 unrotate(
const Unit3& p, boost::optional<Matrix&> HR = boost::none,
347 boost::optional<Matrix&> Hp = boost::none)
const;
357 Matrix3 matrix()
const;
360 Matrix3 transpose()
const;
393 inline double roll()
const {
return ypr()(2); }
401 inline double pitch()
const {
return ypr()(1); }
409 inline double yaw()
const {
return ypr()(0); }
424 Vector quaternion()
const;
427 GTSAM_EXPORT
friend std::ostream &operator<<(std::ostream &os,
const Rot3& p);
431 friend class boost::serialization::access;
432 template<
class ARCHIVE>
433 void serialize(ARCHIVE & ar,
const unsigned int version)
435 ar & boost::serialization::make_nvp(
"Rot3",
436 boost::serialization::base_object<Value>(*
this));
437 #ifndef GTSAM_USE_QUATERNIONS
438 ar & boost::serialization::make_nvp(
"rot11", rot_(0,0));
439 ar & boost::serialization::make_nvp(
"rot12", rot_(0,1));
440 ar & boost::serialization::make_nvp(
"rot13", rot_(0,2));
441 ar & boost::serialization::make_nvp(
"rot21", rot_(1,0));
442 ar & boost::serialization::make_nvp(
"rot22", rot_(1,1));
443 ar & boost::serialization::make_nvp(
"rot23", rot_(1,2));
444 ar & boost::serialization::make_nvp(
"rot31", rot_(2,0));
445 ar & boost::serialization::make_nvp(
"rot32", rot_(2,1));
446 ar & boost::serialization::make_nvp(
"rot33", rot_(2,2));
448 ar & boost::serialization::make_nvp(
"w", quaternion_.w());
449 ar & boost::serialization::make_nvp(
"x", quaternion_.x());
450 ar & boost::serialization::make_nvp(
"y", quaternion_.y());
451 ar & boost::serialization::make_nvp(
"z", quaternion_.z());
468 GTSAM_EXPORT std::pair<Matrix3,Vector3>
RQ(
const Matrix3& A);
static size_t Dim()
dimension of the variable - used to autodetect sizes
Definition: Rot3.h:250
pair< Matrix3, Vector3 > RQ(const Matrix3 &A)
[RQ] receives a 3 by 3 matrix and returns an upper triangular matrix R and 3 rotation angles correspo...
Definition: Rot3.cpp:211
Matrix inverse(const Matrix &A)
invert A
Definition: Matrix.cpp:289
Rot3 conjugate(const Rot3 &cRb) const
Conjugation: given a rotation acting in frame B, compute rotation c1Rc2 acting in a frame C...
Definition: Rot3.h:233
static Rot3 quaternion(double w, double x, double y, double z)
Create from Quaternion coefficients.
Definition: Rot3.h:153
double roll() const
Accessor to get to component of angle representations NOTE: these are not efficient to get to multipl...
Definition: Rot3.h:393
static Rot3 identity()
identity rotation for group operation
Definition: Rot3.h:214
static Rot3 ypr(double y, double p, double r)
Returns rotation nRb from body to nav frame.
Definition: Rot3.h:150
double pitch() const
Accessor to get to component of angle representations NOTE: these are not efficient to get to multipl...
Definition: Rot3.h:401
Use the Lie group exponential map to retract.
Definition: Rot3.h:265
Retract and localCoordinates using the Cayley transform.
Definition: Rot3.h:267
static Rot3 rodriguez(double wx, double wy, double wz)
Rodriguez' formula to compute an incremental rotation matrix.
Definition: Rot3.h:196
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:249
bool zero(const Vector &v)
check if all zero
Definition: Vector.cpp:39
double yaw() const
Accessor to get to component of angle representations NOTE: these are not efficient to get to multipl...
Definition: Rot3.h:409
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Rot3 inverse(boost::optional< Matrix & > H1=boost::none) const
derivative of inverse rotation R^T s.t. inverse(R)*R = identity
Definition: Rot3M.cpp:160
Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
Typedef to an Eigen Quaternion<double>, we disable alignment because geometry objects are stored in b...
Definition: Rot3.h:52
Represents a 3D point on a unit sphere.
Definition: Unit3.h:31
CoordinatesMode
The method retract() is used to map from the tangent space back to the manifold.
Definition: Rot3.h:264
Template to create a binary predicate.
Definition: Testable.h:102
virtual ~Rot3()
Virtual destructor.
Definition: Rot3.h:110
static Rot3 yaw(double t)
Positive yaw is to right (as in aircraft heading). See ypr.
Definition: Rot3.h:133
typedef and functions to augment Eigen's MatrixXd
static Rot3 pitch(double t)
Positive pitch is up (increasing aircraft altitude).See ypr.
Definition: Rot3.h:136
static Rot3 RzRyRx(const Vector &xyz)
Rotations around Z, Y, then X axes as in http://en.wikipedia.org/wiki/Rotation_matrix, counterclockwise when looking from unchanging axis.
Definition: Rot3.h:127
static Rot3 Expmap(const Vector &v)
Exponential map at identity - create a rotation from canonical coordinates using Rodriguez' formula...
Definition: Rot3.h:291
size_t dim() const
return dimensionality of tangent space, DOF = 3
Definition: Rot3.h:253
Definition: DerivedValue.h:44
const MATRIX::ConstColXpr column(const MATRIX &A, size_t j)
Extracts a column view from a matrix that avoids a copy.
Definition: Matrix.h:235