21 #include <boost/optional.hpp>
23 #include <gtsam/base/DerivedValue.h>
38 static const size_t dimension = 1;
50 inline Rot2(
double c,
double s) :
66 c_(cos(theta)), s_(sin(theta)) {
76 const double degree = M_PI / 180;
77 return fromAngle(theta * degree);
81 static Rot2 fromCosSin(
double c,
double s);
90 static Rot2 relativeBearing(
const Point2& d, boost::optional<Matrix&> H =
94 static Rot2 atan2(
double y,
double x);
101 void print(
const std::string& s =
"theta")
const;
104 bool equals(
const Rot2& R,
double tol = 1e-9)
const;
115 return Rot2(c_, -s_);
120 boost::none, boost::optional<Matrix&> H2 = boost::none)
const {
121 if (H1) *H1 =
eye(1);
122 if (H2) *H2 =
eye(1);
123 return fromCosSin(c_ * R.c_ - s_ * R.s_, s_ * R.c_ + c_ * R.s_);
128 return fromCosSin(c_ * R.c_ - s_ * R.s_, s_ * R.c_ + c_ * R.s_);
133 boost::none, boost::optional<Matrix&> H2 = boost::none)
const {
134 if (H1) *H1 = -
eye(1);
135 if (H2) *H2 =
eye(1);
136 return fromCosSin(c_ * R.c_ + s_ * R.s_, -s_ * R.c_ + c_ * R.s_);
144 inline static size_t Dim() {
149 inline size_t dim()
const {
154 inline Rot2 retract(
const Vector& v)
const {
return *
this * Expmap(v); }
173 return (Vector(1) << r.
theta());
183 Point2 rotate(
const Point2& p, boost::optional<Matrix&> H1 = boost::none,
184 boost::optional<Matrix&> H2 = boost::none)
const;
194 Point2 unrotate(
const Point2& p, boost::optional<Matrix&> H1 = boost::none,
195 boost::optional<Matrix&> H2 = boost::none)
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 Matrix matrix()
const;
231 Matrix transpose()
const;
239 friend class boost::serialization::access;
240 template<
class ARCHIVE>
241 void serialize(ARCHIVE & ar,
const unsigned int version) {
242 ar & boost::serialization::make_nvp(
"Rot2",
243 boost::serialization::base_object<Value>(*
this));
244 ar & BOOST_SERIALIZATION_NVP(c_);
245 ar & BOOST_SERIALIZATION_NVP(s_);
Rot2 compose(const Rot2 &R, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
Compose - make a new rotation by adding angles.
Definition: Rot2.h:119
double c() const
return cos
Definition: Rot2.h:218
Point2 operator*(const Point2 &p) const
syntactic sugar for rotate
Definition: Rot2.h:187
Rot2 inverse() const
The inverse rotation - negative angle.
Definition: Rot2.h:114
Matrix eye(size_t m, size_t n)
Creates an identity matrix, with matlab-like syntax.
Definition: Matrix.cpp:50
Rot2 operator*(const Rot2 &R) const
Compose - make a new rotation by adding angles.
Definition: Rot2.h:127
Rot2()
default constructor, zero rotation
Definition: Rot2.h:60
double theta() const
return angle (RADIANS)
Definition: Rot2.h:207
bool zero(const Vector &v)
check if all zero
Definition: Vector.cpp:39
Rot2(double theta)
Constructor from angle in radians == exponential map at identity.
Definition: Rot2.h:65
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
double s() const
return sin
Definition: Rot2.h:223
Rot2 retract(const Vector &v) const
Updates a with tangent space delta.
Definition: Rot2.h:154
Template to create a binary predicate.
Definition: Testable.h:102
Point2 unit() const
Creates a unit vector as a Point2.
Definition: Rot2.h:202
size_t dim() const
Dimensionality of the tangent space, DOF = 1.
Definition: Rot2.h:149
static Rot2 identity()
identity
Definition: Rot2.h:111
static size_t Dim()
dimension of the variable - used to autodetect sizes
Definition: Rot2.h:144
static Rot2 fromDegrees(double theta)
Named constructor from angle in degrees.
Definition: Rot2.h:75
double degrees() const
return angle (DEGREES)
Definition: Rot2.h:212
Vector localCoordinates(const Rot2 &t2) const
Returns inverse retraction.
Definition: Rot2.h:157
static Vector Logmap(const Rot2 &r)
Log map at identity - return the canonical coordinates of this rotation.
Definition: Rot2.h:172
Definition: DerivedValue.h:44
static Rot2 fromAngle(double theta)
Named constructor from angle in radians.
Definition: Rot2.h:70
static Rot2 Expmap(const Vector &v)
Exponential map at identity - create a rotation from canonical coordinates.
Definition: Rot2.h:164
Rot2 between(const Rot2 &R, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
Between using the default implementation.
Definition: Rot2.h:132