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();}
176 #endif // WFMATH_QUATERNION_H Generic library namespace.
Definition: atlasconv.h:45
Quaternion(const Vector< 3 > &axis)
Construct a Quaternion giving a rotation around the Vector axis.
Definition: quaternion.h:63
Quaternion(const Quaternion &p)
Construct a copy of a Quaternion.
Definition: quaternion.h:67
AtlasOutType toAtlas() const
Create an Atlas object from the Quaternion.
Definition: atlasconv.h:154
Quaternion & rotate(const Quaternion &q)
rotate the quaternion using another quaternion
Definition: quaternion.h:140
bool fromRotMatrix(const RotMatrix< 3 > &m)
set a Quaternion's value from a RotMatrix
Quaternion inverse() const
returns the inverse of the Quaternion
unsigned age() const
current round-off age
Definition: quaternion.h:163
Vector & zero()
Zero the components of a vector.
Definition: vector_funcs.h:165
float CoordType
Basic floating point type.
Definition: const.h:140
Quaternion(const AtlasInType &a)
Construct a Quaternion from an Atlas::Message::Object.
Definition: quaternion.h:70
void normalize()
normalize to remove accumulated round-off error
CoordType scalar() const
returns the scalar (w) part of the Quaternion
Definition: quaternion.h:156
Quaternion()
Construct a Quatertion.
Definition: quaternion.h:44
Quaternion(int axis, CoordType angle)
Construct a Quaternion giving a rotation around axis by angle.
Definition: quaternion.h:51
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:121
Quaternion & rotation(int axis, CoordType angle)
sets the Quaternion to a rotation by angle around axis
A normalized quaterion.
Definition: quaternion.h:35
Quaternion(const Vector< 3 > &axis, CoordType angle)
Construct a Quaternion giving a rotation around the Vector axis by angle.
Definition: quaternion.h:55
const Vector< 3 > & vector() const
returns the Vector (x, y, z) part of the quaternion
Definition: quaternion.h:158
Quaternion & identity()
Set the Quaternion to the identity rotation.
Definition: quaternion.h:97