GAMS  1.2.2
Quaternion.h
Go to the documentation of this file.
1 
54 #include "ReferenceFrame.h"
55 
56 #ifndef _GAMS_POSE_QUATERNION_H_
57 #define _GAMS_POSE_QUATERNION_H_
58 
59 #include <iostream>
60 #include <cmath>
61 #include "gams/CPP11_compat.h"
62 
63 namespace gams
64 {
65  namespace pose
66  {
67  class OrientationVector;
68  class PositionVector;
69 
74  class Quaternion
75  {
76  public:
80  constexpr Quaternion() : x_(0), y_(0), z_(0), w_(0) {}
81 
85  constexpr Quaternion(double x, double y, double z, double w);
86 
92  Quaternion(double rx, double ry, double rz);
93 
99  explicit Quaternion(const OrientationVector &rot);
100 
105  explicit Quaternion(const PositionVector &loc);
106 
107  void from_linear_vector(double x, double y, double z);
108 
109  void from_linear_vector(const PositionVector &loc);
110 
111  void to_linear_vector(double &x, double &y, double &z) const;
112 
113  void to_linear_vector(PositionVector &loc) const;
114 
115  void from_angular_vector(double rx, double ry, double rz);
116 
117  void from_angular_vector(const OrientationVector &rot);
118 
119  void to_angular_vector(double &rx, double &ry, double &rz) const;
120 
121  void to_angular_vector(OrientationVector &rot) const;
122 
133  static void hamilton_product(
134  Quaternion &into, const Quaternion &lhs, const Quaternion &rhs);
135 
143  Quaternion &operator*=(const Quaternion &rhs);
144 
151  Quaternion operator*(const Quaternion &rhs) const;
152 
159  void pre_multiply(const Quaternion &lhs)
160  {
161  hamilton_product(*this, lhs, *this);
162  }
163 
170  Quaternion &conjugate();
171 
178  Quaternion &negate();
179 
186  void orient_by(Quaternion rot);
187 
193  constexpr Quaternion operator-() const;
194 
204  double inner_product(const Quaternion &rhs) const;
205 
214  double dot_product(const Quaternion &rhs) const;
215 
224  double angle_to(const Quaternion &target) const;
225 
227  constexpr double x() const;
228 
230  constexpr double y() const;
231 
233  constexpr double z() const;
234 
236  constexpr double w() const;
237 
239  double x(double new_x);
240 
242  double y(double new_y);
243 
245  double z(double new_z);
246 
248  double w(double new_w);
249 
254  void invert();
255 
259  double mag() const;
260 
264  double imag() const;
265 
270  double mag_squared() const;
271 
275  void scale(double s);
276 
283  Quaternion exp() const;
284 
289  void exp_this();
290 
297  Quaternion ln() const;
298 
303  void ln_this();
304 
311  Quaternion pow(double e) const;
312 
317  void pow_this(double e);
318 
325  Quaternion pow(const Quaternion &e) const;
326 
331  void pow_this(const Quaternion &e);
332 
346  Quaternion slerp(const Quaternion &o, double t);
347 
360  void slerp_this(const Quaternion &o, double t);
361 
362  /* The methods below return the cells of the 3x3 orientation matrix this
363  * quaternion represents; names are mRC(), where R is row, and C is column
364  */
365 
367  double m11() const;
368 
370  double m12() const;
371 
373  double m13() const;
374 
376  double m21() const;
377 
379  double m22() const;
380 
382  double m23() const;
383 
385  double m31() const;
386 
388  double m32() const;
389 
391  double m33() const;
392 
393  private:
394  double x_, y_, z_, w_;
395  };
396 
397 
399  const Quaternion &quat)
400  {
401  quat.to_angular_vector(vec()[0], vec()[1], vec()[2]);
402  }
403  }
404 }
405 
406 #include "Quaternion.inl"
407 
408 #endif
Quaternion exp() const
Calculate e to the power of this quaternion, return result as new quaternion.
constexpr double z() const
getter of z (or k) part of quaternion
double m21() const
Row 2 Column 1 of orientation matrix equivalent to this quaternion.
void from_linear_vector(double x, double y, double z)
gams::pose::AngularVector OrientationVector
Container for Orientation information, not bound to a frame.
Definition: Orientation.h:79
double m32() const
Row 3 Column 2 of orientation matrix equivalent to this quaternion.
Quaternion pow(double e) const
Calculate this quaternion raised to a scalar power, return result in a new quaternion.
void to_angular_vector(double &rx, double &ry, double &rz) const
constexpr Quaternion()
Default constructor.
Definition: Quaternion.h:80
double m23() const
Row 2 Column 3 of orientation matrix equivalent to this quaternion.
constexpr double w() const
getter of w (or real scalar) part of quaternion
void ln_this()
Calculate natural log of this quaternion, store result in this quaternion.
double imag() const
Returns the magnitude of imaginary part of this quaternion.
Quaternion & negate()
Flip the sign of all parts of the quaternion; equivalent to (but potentially faster than) this->scale...
void from_angular_vector(double rx, double ry, double rz)
Quaternion & conjugate()
Conjugate this quaternion in-place; may use in place of invert for unit quaternions for better perfor...
Quaternion ln() const
Calculate the natural log of this quaternion, return result in a new quaternion.
Quaternion & operator*=(const Quaternion &rhs)
Calculate hamilton product, this * rhs, and store into this.
Quaternion slerp(const Quaternion &o, double t)
If *this and o are unit quaternions, interpolate a quaternion that is partially between them...
double angle_to(const Quaternion &target) const
Calculates the angle between the orientations represented by this, and the target Quaternion...
double mag() const
Returns the magnitude of this quaternion.
double m31() const
Row 3 Column 1 of orientation matrix equivalent to this quaternion.
double m11() const
Row 1 Column 1 of orientation matrix equivalent to this quaternion.
void invert()
Inverts this quaternion to its reciprical.
void exp_this()
Calculate e to the power of this quaternion, store result in this quaternion.
Contains all GAMS-related tools, classes and code.
double m12() const
Row 1 Column 2 of orientation matrix equivalent to this quaternion.
constexpr Quaternion operator-() const
Copy and conjugate this quaternion.
double mag_squared() const
Returns the magnitude of this quaternion, squared.
double inner_product(const Quaternion &rhs) const
Calculates the Quaternion inner-product between this, and the right-hand-side, which is the sum of th...
void orient_by(Quaternion rot)
Treat this quaternion as a position quaternion (w should be zero), and orient it by the orientation r...
Used internally to implement angle operations.
Definition: Quaternion.h:74
Quaternion operator*(const Quaternion &rhs) const
Calculate hamilton product, this * rhs, and return new Quaternion.
void slerp_this(const Quaternion &o, double t)
If *this and o are unit quaternions, interpolate a quaternion that is partially between them...
double m13() const
Row 1 Column 3 of orientation matrix equivalent to this quaternion.
void to_linear_vector(double &x, double &y, double &z) const
void pre_multiply(const Quaternion &lhs)
Calculate hamilton product, lhs * this, and store into this.
Definition: Quaternion.h:159
double m33() const
Row 3 Column 3 of orientation matrix equivalent to this quaternion.
constexpr double x() const
getter of x (or i) part of quaternion
double dot_product(const Quaternion &rhs) const
Calculates the Quaternion dot product between this, and the right-hand-side; this is the inner-produc...
void pow_this(double e)
Calculate this quaternion raised to a scalar power, store result in this quaternion.
constexpr double y() const
getter of y (or j) part of quaternion
static void hamilton_product(Quaternion &into, const Quaternion &lhs, const Quaternion &rhs)
Calculates the hamilton product of two quaternions, into a third.
double m22() const
Row 2 Column 2 of orientation matrix equivalent to this quaternion.
void scale(double s)
Multiply each part of this quaternion by s.