gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Unit3.h
1 /* ----------------------------------------------------------------------------
2 
3  * Atlanta, Georgia 30332-0415
4  * All Rights Reserved
5  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
12 /*
13  * @file Unit3.h
14  * @date Feb 02, 2011
15  * @author Can Erdogan
16  * @author Frank Dellaert
17  * @author Alex Trevor
18  * @brief Develop a Unit3 class - basically a point on a unit sphere
19  */
20 
21 #pragma once
22 
23 #include <gtsam/geometry/Point3.h>
24 #include <gtsam/base/DerivedValue.h>
25 #include <boost/random/mersenne_twister.hpp>
26 #include <boost/optional.hpp>
27 
28 namespace gtsam {
29 
31 class GTSAM_EXPORT Unit3: public DerivedValue<Unit3> {
32 
33 private:
34 
35  typedef Eigen::Matrix<double,3,2> Matrix32;
36 
37  Point3 p_;
38  mutable boost::optional<Matrix32> B_;
39 
40 public:
41 
44 
46  Unit3() :
47  p_(1.0, 0.0, 0.0) {
48  }
49 
51  explicit Unit3(const Point3& p) :
52  p_(p / p.norm()) {
53  }
54 
56  Unit3(double x, double y, double z) :
57  p_(x, y, z) {
58  p_ = p_ / p_.norm();
59  }
60 
62  static Unit3 FromPoint3(const Point3& point, boost::optional<Matrix&> H =
63  boost::none);
64 
66  static Unit3 Random(boost::mt19937 & rng);
67 
69 
72 
74  void print(const std::string& s = std::string()) const;
75 
77  bool equals(const Unit3& s, double tol = 1e-9) const {
78  return p_.equals(s.p_, tol);
79  }
81 
84 
90  const Matrix32& basis() const;
91 
93  Matrix skew() const;
94 
96  const Point3& point3(boost::optional<Matrix&> H = boost::none) const {
97  if (H)
98  *H = basis();
99  return p_;
100  }
101 
103  friend Point3 operator*(double s, const Unit3& d) {
104  return s * d.p_;
105  }
106 
108  Vector error(const Unit3& q,
109  boost::optional<Matrix&> H = boost::none) const;
110 
112  double distance(const Unit3& q,
113  boost::optional<Matrix&> H = boost::none) const;
114 
116 
119 
121  inline static size_t Dim() {
122  return 2;
123  }
124 
126  inline size_t dim() const {
127  return 2;
128  }
129 
132  RENORM
133  };
134 
136  Unit3 retract(const Vector& v) const;
137 
139  Vector localCoordinates(const Unit3& s) const;
140 
142 
143 private:
144 
147 
149  friend class boost::serialization::access;
150  template<class ARCHIVE>
151  void serialize(ARCHIVE & ar, const unsigned int version) {
152  ar & boost::serialization::make_nvp("Unit3",
153  boost::serialization::base_object<Value>(*this));
154  ar & BOOST_SERIALIZATION_NVP(p_);
155  ar & BOOST_SERIALIZATION_NVP(B_);
156  }
157 
159 
160 };
161 
162 } // namespace gtsam
163 
const Point3 & point3(boost::optional< Matrix & > H=boost::none) const
Return unit-norm Point3.
Definition: Unit3.h:96
friend Point3 operator*(double s, const Unit3 &d)
Return scaled direction as Point3.
Definition: Unit3.h:103
Unit3(const Point3 &p)
Construct from point.
Definition: Unit3.h:51
Unit3(double x, double y, double z)
Construct from x,y,z.
Definition: Unit3.h:56
static size_t Dim()
Dimensionality of tangent space = 2 DOF.
Definition: Unit3.h:121
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Represents a 3D point on a unit sphere.
Definition: Unit3.h:31
size_t dim() const
Dimensionality of tangent space = 2 DOF.
Definition: Unit3.h:126
Vector basis(size_t n, size_t i)
Create basis vector of dimension n, with one in spot i.
Definition: Vector.h:68
CoordinatesMode
Definition: Unit3.h:130
bool equals(const Unit3 &s, double tol=1e-9) const
The equals function with tolerance.
Definition: Unit3.h:77
3D Point
Definition: DerivedValue.h:44
Definition: Point3.h:39
Use the exponential map to retract.
Definition: Unit3.h:131
Unit3()
Default constructor.
Definition: Unit3.h:46