26#ifndef WFMATH_QUATERNION_H
27#define WFMATH_QUATERNION_H
29#include <wfmath/vector.h>
30#include <wfmath/rotmatrix.h>
40 Quaternion(
const Identity &) : m_w(1), m_vec(), m_valid(
true), m_age(0) {
44 Quaternion () : m_w(0), m_vec(), m_valid(false), m_age(0) {}
64 m_valid(false), m_age(0)
68 m_valid(p.m_valid), m_age(p.m_age) {}
70 explicit Quaternion (
const AtlasInType& a) : m_w(0), m_vec(),
71 m_valid(false), m_age(0)
76 friend std::ostream& operator<<(std::ostream& os,
const Quaternion& p);
77 friend std::istream& operator>>(std::istream& is,
Quaternion& p);
85 {m_w = rhs.m_w; m_vec = rhs.m_vec; m_valid = rhs.m_valid; m_age = rhs.m_age;
return *
this;}
89 bool isEqualTo(
const Quaternion &q,
CoordType epsilon = numeric_constants<CoordType>::epsilon())
const;
91 bool operator== (
const Quaternion& rhs)
const {
return isEqualTo(rhs);}
92 bool operator!= (
const Quaternion& rhs)
const {
return !isEqualTo(rhs);}
94 bool isValid()
const {
return m_valid;}
163 unsigned age()
const {
return m_age;}
166 Quaternion(
bool valid) : m_w(0), m_vec(), m_valid(valid), m_age(1) {}
167 void checkNormalization() {
if(m_age >= WFMATH_MAX_NORM_AGE && m_valid)
normalize();}
A normalized quaterion.
Definition quaternion.h:36
Quaternion(const AtlasInType &a)
Construct a Quaternion from an Atlas::Message::Object.
Definition quaternion.h:70
Quaternion(const Quaternion &p)
Construct a copy of a Quaternion.
Definition quaternion.h:67
Quaternion inverse() const
returns the inverse of the Quaternion
CoordType scalar() const
returns the scalar (w) part of the Quaternion
Definition quaternion.h:156
Quaternion & rotation(const Vector< 3 > &axis)
sets the Quaternion to a rotation around the Vector axis
void normalize()
normalize to remove accumulated round-off error
bool fromRotMatrix(const RotMatrix< 3 > &m)
set a Quaternion's value from a RotMatrix
void fromAtlas(const AtlasInType &a)
Set the Quaternion's value to that given by an Atlas object.
Definition atlasconv.h:121
Quaternion & rotation(const Vector< 3 > &from, const Vector< 3 > &to)
sets the Quaternion to rotate 'from' to be parallel to 'to'
Quaternion & rotate(const Quaternion &q)
rotate the quaternion using another quaternion
Definition quaternion.h:140
Quaternion(CoordType w_in, CoordType x_in, CoordType y_in, CoordType z_in)
Construct a Quaternion from (w, x, y, z) components.
Quaternion & rotate(const RotMatrix< 3 > &)
Rotate quaternion using the matrix.
Quaternion(const Vector< 3 > &axis, CoordType angle)
Construct a Quaternion giving a rotation around the Vector axis by angle.
Definition quaternion.h:55
unsigned age() const
current round-off age
Definition quaternion.h:163
Quaternion & rotation(const Vector< 3 > &axis, CoordType angle)
sets the Quaternion to a rotation by angle around the Vector axis
Quaternion & rotation(int axis, CoordType angle)
sets the Quaternion to a rotation by angle around axis
Quaternion(int axis, CoordType angle)
Construct a Quaternion giving a rotation around axis by angle.
Definition quaternion.h:51
Quaternion()
Construct a Quatertion.
Definition quaternion.h:44
AtlasOutType toAtlas() const
Create an Atlas object from the Quaternion.
Definition atlasconv.h:154
const Vector< 3 > & vector() const
returns the Vector (x, y, z) part of the quaternion
Definition quaternion.h:158
Quaternion(const Vector< 3 > &axis)
Construct a Quaternion giving a rotation around the Vector axis.
Definition quaternion.h:63
Quaternion & identity()
Set the Quaternion to the identity rotation.
Definition quaternion.h:97
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
Definition rotmatrix.h:87
A dim dimensional vector.
Definition vector.h:121
Vector & zero()
Zero the components of a vector.
Definition vector_funcs.h:165
Generic library namespace.
Definition atlasconv.h:45
float CoordType
Basic floating point type.
Definition const.h:140