26 #ifndef WFMATH_QUATERNION_H
27 #define WFMATH_QUATERNION_H
29 #include <wfmath/vector.h>
30 #include <wfmath/rotmatrix.h>
43 Quaternion () : m_w(0), m_vec(), m_valid(false), m_age(0) {}
63 m_valid(false), m_age(0)
67 m_valid(p.m_valid), m_age(p.m_age) {}
69 explicit Quaternion (
const AtlasInType& a) : m_w(0), m_vec(),
70 m_valid(false), m_age(0)
75 friend std::ostream& operator<<(std::ostream& os,
const Quaternion& p);
76 friend std::istream& operator>>(std::istream& is,
Quaternion& p);
84 {m_w = rhs.m_w; m_vec = rhs.m_vec; m_valid = rhs.m_valid; m_age = rhs.m_age;
return *
this;}
88 bool isEqualTo(
const Quaternion &q,
double epsilon = WFMATH_EPSILON)
const;
90 bool operator== (
const Quaternion& rhs)
const {
return isEqualTo(rhs);}
91 bool operator!= (
const Quaternion& rhs)
const {
return !isEqualTo(rhs);}
93 bool isValid()
const {
return m_valid;}
162 unsigned age()
const {
return m_age;}
165 Quaternion(
bool valid) : m_w(0), m_vec(), m_valid(valid), m_age(1) {}
166 void checkNormalization() {
if(m_age >= WFMATH_MAX_NORM_AGE && m_valid)
normalize();}
175 #endif // WFMATH_QUATERNION_H
Quaternion(const Vector< 3 > &axis)
Construct a Quaternion giving a rotation around the Vector axis.
Definition: quaternion.h:62
Quaternion(const Quaternion &p)
Construct a copy of a Quaternion.
Definition: quaternion.h:66
CoordType scalar() const
returns the scalar (w) part of the Quaternion
Definition: quaternion.h:155
Quaternion inverse() const
returns the inverse of the Quaternion
const Vector< 3 > & vector() const
returns the Vector (x, y, z) part of the quaternion
Definition: quaternion.h:157
Quaternion & rotate(const Quaternion &q)
rotate the quaternion using another quaternion
Definition: quaternion.h:139
bool fromRotMatrix(const RotMatrix< 3 > &m)
set a Quaternion's value from a RotMatrix
Vector & zero()
Zero the components of a vector.
Definition: vector_funcs.h:212
float CoordType
Basic floating point type.
Definition: const.h:79
Quaternion(const AtlasInType &a)
Construct a Quaternion from an Atlas::Message::Object.
Definition: quaternion.h:69
AtlasOutType toAtlas() const
Create an Atlas object from the Quaternion.
Definition: atlasconv.h:162
void normalize()
normalize to remove accumulated round-off error
Quaternion()
Construct a Quatertion.
Definition: quaternion.h:43
Quaternion(int axis, CoordType angle)
Construct a Quaternion giving a rotation around axis by angle.
Definition: quaternion.h:50
Quaternion & rotate(const RotMatrix< 3 > &)
Rotate quaternion using the matrix.
void fromAtlas(const AtlasInType &a)
Set the Quaternion's value to that given by an Atlas object.
Definition: atlasconv.h:129
Quaternion & rotation(int axis, CoordType angle)
sets the Quaternion to a rotation by angle around axis
A normalized quaterion.
Definition: quaternion.h:39
Quaternion(const Vector< 3 > &axis, CoordType angle)
Construct a Quaternion giving a rotation around the Vector axis by angle.
Definition: quaternion.h:54
unsigned age() const
current round-off age
Definition: quaternion.h:162
Quaternion & identity()
Set the Quaternion to the identity rotation.
Definition: quaternion.h:96