45 inline Rot2(
double c,
double s) : c_(
c), s_(
s) {}
53 Rot2() : c_(1.0), s_(0.0) {}
56 Rot2(
const Rot2& r) =
default;
58 Rot2& operator=(
const Rot2& other) =
default;
72 static const double degree = M_PI / 180;
77 static Rot2 fromCosSin(
double c,
double s);
90 static Rot2 atan2(
double y,
double x);
98 static Rot2 Random(std::mt19937 & rng);
105 void print(
const std::string& s =
"theta")
const;
108 bool equals(
const Rot2& R,
double tol = 1e-9)
const;
122 return fromCosSin(c_ * R.c_ - s_ * R.s_, s_ * R.c_ + c_ * R.s_);
129 using LieAlgebra = Matrix2;
132 static Rot2 Expmap(
const Vector1& v, ChartJacobian H = {});
135 static Vector1 Logmap(
const Rot2& r, ChartJacobian H = {});
141 static Matrix1 adjointMap(
const Vector1&);
144 static Vector1 adjoint(
const Vector1&,
const Vector1&,
146 OptionalJacobian<1, 1> Hy = {});
160 static Rot2 Retract(
const Vector1& v, ChartJacobian H = {}) {
163 static Vector1 Local(
const Rot2& r, ChartJacobian H = {}) {
171 static Matrix2
Hat(
const Vector1& xi);
174 static Vector1
Vee(
const Matrix2& X);
195 OptionalJacobian<2, 2> H2 = {})
const;
208 return ::atan2(s_, c_);
213 const double degree = M_PI / 180;
214 return theta() / degree;
218 inline double c()
const {
223 inline double s()
const {
228 Matrix2 matrix()
const;
231 Matrix2 transpose()
const;
234 static Rot2 ClosestTo(
const Matrix2& M);
241#if GTSAM_ENABLE_BOOST_SERIALIZATION
243 friend class boost::serialization::access;
244 template<
class ARCHIVE>
245 void serialize(ARCHIVE & ar,
const unsigned int ) {
246 ar & BOOST_SERIALIZATION_NVP(c_);
247 ar & BOOST_SERIALIZATION_NVP(s_);
269 if constexpr (D == 1) {
270 return Vector3(1.0, value.
c(), value.
s());
271 }
else if constexpr (D >= 2) {
272 Matrix X = Matrix::Zero(2, D);
273 X.leftCols<2>() = value.
matrix().transpose();
276 throw std::invalid_argument(
277 "traits<Rot2>::QcqpValue requires D>=1.");
291 if constexpr (D == 1) {
293 std::vector<std::pair<Matrix, double>> constraints;
294 constraints.reserve(2);
300 constraints.emplace_back(A, 1.0);
306 constraints.emplace_back(A, 1.0);
309 }
else if constexpr (D >= 2) {
310 std::vector<std::pair<Matrix, double>> constraints;
311 constraints.reserve(3);
313 Matrix A = Matrix::Zero(2, 2);
315 constraints.emplace_back(A, 1.0);
319 constraints.emplace_back(A, 1.0);
324 constraints.emplace_back(A, 0.0);
328 throw std::invalid_argument(
329 "traits<Rot2>::QcqpConstraints only supports D=1 and D>=2.");
342 if constexpr (D == 1) {
344 std::abs(X(0, 0)) < 1e-9) {
345 throw std::invalid_argument(
346 "traits<Rot2>::FromQcqpValue requires a 3-by-1 vector with a "
347 "nonzero homogenization entry.");
349 const Vector x = X.col(0) / X(0, 0);
352 static_assert(D >= 2,
353 "traits<Rot2>::FromQcqpValue requires D >= 2.");
354 if (X.rows() != 2 || X.cols() != D) {
355 throw std::invalid_argument(
356 "traits<Rot2>::FromQcqpValue requires a 2-by-D matrix.");
Base class and basic functions for Matrix Lie groups.
typedef and functions to augment Eigen's MatrixXd
Macros for Matrix constants to avoid excessive template instantiation.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Vector2 Point2
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point2 to Vector2...
Definition Point2.h:32
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A CRTP helper class that implements Lie group methods Prerequisites: methods operator*,...
Definition Lie.h:114
A CRTP helper class that implements matrix Lie group methods.
Definition MatrixLieGroup.h:51
Both LieGroupTraits and Testable.
Definition MatrixLieGroup.h:350
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
Rotation matrix NOTE: the angle theta is in radians unless explicitly stated.
Definition Rot2.h:40
Rot2 operator*(const Rot2 &R) const
Compose - make a new rotation by adding angles.
Definition Rot2.h:121
double c() const
return cos
Definition Rot2.h:218
static Matrix ExpmapDerivative(const Vector &)
Left-trivialized derivative of the exponential map.
Definition Rot2.h:149
Point2 unit() const
Creates a unit vector as a Point2.
Definition Rot2.h:202
double theta() const
return angle (RADIANS)
Definition Rot2.h:207
Rot2 inverse() const
The inverse rotation - negative angle.
Definition Rot2.h:118
Point2 operator*(const Point2 &p) const
syntactic sugar for rotate
Definition Rot2.h:187
static Rot2 fromCosSin(double c, double s)
Named constructor from cos(theta),sin(theta) pair.
Definition Rot2.cpp:30
double s() const
return sin
Definition Rot2.h:223
Rot2(const Rot2 &r)=default
copy constructor
static Rot2 Expmap(const Vector1 &v, ChartJacobian H={})
Exponential map at identity - create a rotation from canonical coordinates.
Definition Rot2.cpp:63
static Rot2 Identity()
Identity.
Definition Rot2.h:115
double degrees() const
return angle (DEGREES)
Definition Rot2.h:212
static Matrix LogmapDerivative(const Vector &)
Left-trivialized derivative inverse of the exponential map.
Definition Rot2.h:154
Matrix1 AdjointMap() const
Calculate Adjoint map.
Definition Rot2.h:138
static Matrix2 Hat(const Vector1 &xi)
Hat maps from tangent vector to Lie algebra.
Definition Rot2.cpp:92
static Vector1 Logmap(const Rot2 &r, ChartJacobian H={})
Log map at identity - return the canonical coordinates of this rotation.
Definition Rot2.cpp:73
Matrix2 matrix() const
return 2*2 rotation matrix
Definition Rot2.cpp:100
Rot2(double theta)
Constructor from angle in radians == exponential map at identity.
Definition Rot2.h:61
static Rot2 fromDegrees(double theta)
Named constructor from angle in degrees.
Definition Rot2.h:71
Point2 rotate(const Point2 &p, OptionalJacobian< 2, 1 > H1={}, OptionalJacobian< 2, 2 > H2={}) const
rotate point from rotated coordinate frame to world
Definition Rot2.cpp:107
Rot2()
default constructor, zero rotation
Definition Rot2.h:53
static Vector1 Vee(const Matrix2 &X)
Vee maps from Lie algebra to tangent vector.
Definition Rot2.cpp:97
static Rot2 ClosestTo(const Matrix2 &M)
Find closest valid rotation matrix, given a 2x2 matrix.
Definition Rot2.cpp:140
static Rot2 fromAngle(double theta)
Named constructor from angle in radians.
Definition Rot2.h:66
static Rot2 atan2(double y, double x)
Named constructor that behaves as atan2, i.e., y,x order (!) and normalizes.
Definition Rot2.cpp:41
static std::vector< std::pair< Matrix, double > > QcqpConstraints()
Return row-space QCQP equality constraints A, b such that trace(x_i' A x_i) = b[j].
Definition Rot2.h:290
static constexpr int QcqpVectorDim
Dimension of the D=1 homogenized QCQP vector [h, cos(theta), sin(theta)].
Definition Rot2.h:256
static Matrix QcqpValue(const Rot2 &value)
Return a matrix-valued QCQP variable for Rot2.
Definition Rot2.h:268
static Rot2 FromQcqpValue(const Matrix &X)
Project a D=1 minimal vector or canonical 2-by-D lift back to Rot2.
Definition Rot2.h:341