25 Quat2(
const double &a): ang_(a) { }
33 void setQuat(
const double &a){ ang_ = a; }
36 const double &
ang()
const {
return ang_; }
39 double &
rang() {
return ang_; }
57 BASE_EXPORT void fromEuler(
const DAVect2 &v) { *
this =
Quat2(v.z()) * dDegrad; }
58 BASE_EXPORT void fromEulerZXZ(
const DAVect2& v) { *
this =
Quat2(v.z()) * dDegrad; }
112 Quat3(): w_(0), i_(0), j_(0), k_(0) { }
115 Quat3(
const double &w1,
const double &x,
const double &y,
const double &z) { w_ = w1; i_ = x; j_ = y; k_ = z; }
119 Quat3(
const Quat3 &q) { w_ = q.w_; i_ = q.i_; j_ = q.j_; k_ = q.k_; }
121 constexpr
const Quat3 &
operator=(
const Quat3 &q) { w_ = q.w_; i_ = q.i_; j_ = q.j_; k_ = q.k_;
return *
this; }
123 void setQuat(
const double &w1,
const double &x,
const double &y,
const double &z){ w_ = w1; i_ = x; j_ = y; k_ = z; }
126 const double &
w()
const {
return w_; }
128 const double &
i()
const {
return i_; }
130 const double &
j()
const {
return j_; }
132 const double &
k()
const {
return k_; }
135 double &
rw() {
return w_; }
137 double &
ri() {
return i_; }
139 double &
rj() {
return j_; }
141 double &
rk() {
return k_; }
144 void reset() { w_=0.0; i_=0.0; j_=0.0; k_=0.0; }
146 void ident() { w_=1.0; i_=0.0; j_=0.0; k_=0.0; }
150 BASE_EXPORT bool isNull()
const {
return (abs(w_) > std::numeric_limits<double>::epsilon() || abs(i_) > std::numeric_limits<double>::epsilon() || abs(j_) > std::numeric_limits<double>::epsilon() || abs(k_) > std::numeric_limits<double>::epsilon()) ? false :
true; }
195 void conj() { i_=-i_; j_=-j_; k_=-k_; }
208 Quat3 operator *(
const Quat3 &v)
const {
Quat3 q(w_*v.w_-i_*v.i_-j_*v.j_-k_*v.k_,w_*v.i_+i_*v.w_+j_*v.k_-k_*v.j_,w_*v.j_-i_*v.k_+j_*v.w_+k_*v.i_,w_*v.k_+i_*v.j_-j_*v.i_+k_*v.w_);
return q; }
217 const Quat3 &
operator *=(
const double &d) { w_ *= d; i_ *= d; j_ *= d; k_ *= d;
return *
this; }
219 const Quat3 &
operator /=(
const double &d) { w_ /= d; i_ /= d; j_ /= d; k_ /= d;
return *
this; }
222 double ti(w_*v.i_+i_*v.w_+j_*v.k_-k_*v.j_);
223 double tj(w_*v.j_-i_*v.k_+j_*v.w_+k_*v.i_);
224 double tk(w_*v.k_+i_*v.j_-j_*v.i_+k_*v.w_);
229 w_ = tw; i_ = ti; j_ = tj; k_ = tk;
234 bool operator ==(
const Quat3 &v)
const {
return (w_ == v.w_ && i_==v.i_ && j_==v.j_ && k_==v.k_); }
242 BASE_EXPORT string ts(
const Quat2 &q,
int width=0,
char notation =
'\0',
int precision = -1,
char fill =
' ');
244 BASE_EXPORT string ts(
const Quat3 &q,
int width=0,
char notation =
'\0',
int precision = -1,
char fill =
' ');
DMatrix is a Matrix that defaults to type double...
Definition: matrix.h:741
2D quaternion-like utility class. In this case only the angle (in radians) is stored as opposed to th...
Definition: quat.h:20
Quat2 operator+(const Quat2 &v) const
Addition of quaterions. This is also the composition of rotations in 2D.
Definition: quat.h:88
BASE_EXPORT void fromUnitAxes(const DVect2 &, const DVect2 &)
Definition: quat.cpp:62
BASE_EXPORT void incrementAxisAngle(const DVect2 &, const double &)
Increment by this rotation. In this case the axis is ignored.
Definition: quat.cpp:49
const double & ang() const
Access the angle.
Definition: quat.h:36
Quat2 operator*(const double &d) const
Multiplication by a double.
Definition: quat.h:79
const Quat2 & operator*=(const double &d)
In place multiplaction by a double.
Definition: quat.h:91
void conj()
Convert to the conjugate quaternion - rotation by the opposite sign.
Definition: quat.h:72
void setQuat(const double &a)
Set the angle.
Definition: quat.h:33
Quat2(const double &a)
Constructor initializing the angle.
Definition: quat.h:25
static BASE_EXPORT Quat2 identity()
Return the identity quaternion.
Definition: quat.h:46
Quat2(const Quat2 &q)
Copy constructor.
Definition: quat.h:29
Quat2 getConj() const
Return the conjugate of the quaternion.
Definition: quat.h:74
Quat2()
Default constructor.
Definition: quat.h:23
static BASE_EXPORT Quat2 fromVect(const DVect2 &v)
Convert a DVect2 into a quaternion. This assumes a rotation from the positive x axis.
Definition: quat.cpp:17
BASE_EXPORT void fromMatrix(const DMatrix< 2, 2 > &)
Convert a matrix into a quaternion.
Definition: quat.cpp:21
BASE_EXPORT void spinAboutZ(const double &)
Just spin about the Z axis.
Definition: quat.cpp:53
BASE_EXPORT void increment(const DAVect2 &)
Increment the quaternion due to a rotation about Z by the DAVect.
Definition: quat.cpp:66
~Quat2()
Destructor.
Definition: quat.h:27
BASE_EXPORT void fromAxisAngle(const DVect2 &, const double &)
Definition: quat.cpp:45
bool operator==(const Quat2 &v) const
Euality operator.
Definition: quat.h:101
void reset()
Reset the angle to 0.
Definition: quat.h:42
constexpr Quat2 & operator=(const Quat2 &in)
Equals operator.
Definition: quat.h:31
BASE_EXPORT DMatrix< 2, 2 > quatToMatrix() const
Convert the quaternion to a rotation matrix.
Definition: quat.cpp:6
double & rang()
Access a reference to the angle.
Definition: quat.h:39
void normalize()
Normalize the quaternion.
Definition: quat.h:76
const Quat2 & operator+=(const Quat2 &v)
Definition: quat.h:99
BASE_EXPORT DVect2 rotate(const DVect2 &v) const
Rotate a DVect2 by the quaternian to get a new DVect2.
Definition: quat.cpp:57
void ident()
Reset to the identity.
Definition: quat.h:44
const Quat2 & operator/=(const double &d)
In place division by a double.
Definition: quat.h:93
Quat2 operator/(const double &d) const
Division by a double.
Definition: quat.h:81
3D quaternion utility class.
Definition: quat.h:109
Quat3(const Quat3 &q)
Copy constructor.
Definition: quat.h:119
BASE_EXPORT DVect3 rotate(const DVect3 &v) const
Rotate a DVect3 by the quaternian to get a new DVect3.
Definition: quat.cpp:221
BASE_EXPORT void increment(const DAVect3 &)
Increment the quaternion due to a rotation about the x, y, and z axes by the DAVect.
Definition: quat.cpp:257
Quat3 getConj() const
Return the conjugate of the quaternion.
Definition: quat.h:197
constexpr const Quat3 & operator=(const Quat3 &q)
Equality operator.
Definition: quat.h:121
void setQuat(const double &w1, const double &x, const double &y, const double &z)
Set the real and imaginary parts.
Definition: quat.h:123
void conj()
Convert the quaternion to the conjugate.
Definition: quat.h:195
static BASE_EXPORT Quat3 fromVect(const DVect3 &v)
Convert a DVect3 into a quaternion.
Definition: quat.cpp:119
Quat3 operator+(const Quat3 &v) const
Addition of two quaternions.
Definition: quat.h:210
double & rj()
Access a reference to the second imaginary part.
Definition: quat.h:139
const double & k() const
Access the third imaginary part.
Definition: quat.h:132
BASE_EXPORT void incrementAxisAngle(const DVect3 &, const double &)
Increment by this rotation.
Definition: quat.cpp:203
const double & j() const
Access the second imaginary part.
Definition: quat.h:130
BASE_EXPORT DVect3 e1() const
Get component e1 of the rotation matrix.
Definition: quat.cpp:261
~Quat3()
Default destructor.
Definition: quat.h:117
const Quat3 & operator+=(const Quat3 &v)
In place addition of two quaternions.
Definition: quat.h:232
Quat3 operator*(const double &d) const
Multiplication by a double.
Definition: quat.h:202
BASE_EXPORT bool isNull() const
Returns a boolean indicating whether or not the quaternion is null.
Definition: quat.h:150
BASE_EXPORT void fromEuler(const DVect3 &)
Definition: quat.cpp:173
static BASE_EXPORT Quat3 identity()
Returns the identity quaternion.
Definition: quat.h:148
BASE_EXPORT void fromUnitAxes(const DVect3 &, const DVect3 &)
Take 2 orthogonal axis for an axis system and convert to a quaternion.
Definition: quat.cpp:227
void ident()
Reset the quaternion to the identity.
Definition: quat.h:146
BASE_EXPORT DVect3 quatToAAngle() const
Convert to Axis Angle where the magnitude of the axis is the angle in radians.
Definition: quat.cpp:98
Quat3()
Default constructor.
Definition: quat.h:112
BASE_EXPORT void spinAboutY(const double &)
Just spin about the Y axis.
Definition: quat.cpp:213
const double & w() const
Access the real part.
Definition: quat.h:126
BASE_EXPORT DVect3 e3() const
Get component e3 of the rotation matrix.
Definition: quat.cpp:269
Quat3(const double &w1, const double &x, const double &y, const double &z)
Definition: quat.h:115
BASE_EXPORT DVect3 e2() const
Get component e2 of the rotation matrix.
Definition: quat.cpp:265
BASE_EXPORT DVect3 real() const
Return the "real" vector part of the quaternian.
Definition: quat.h:178
void reset()
Reset the quaternion.
Definition: quat.h:144
BASE_EXPORT void spinAboutX(const double &)
Just spin about the X axis.
Definition: quat.cpp:209
const Quat3 & operator/=(const double &d)
In place division by a double.
Definition: quat.h:219
BASE_EXPORT void fromAxisAngle(const DVect3 &, const double &)
Take an axis-angle representation and convert it to a quaternion where the angle is in radians.
Definition: quat.cpp:159
BASE_EXPORT DMatrix< 3, 3 > quatToMatrix() const
Convert the quaternion to a rotation matrix.
Definition: quat.cpp:70
BASE_EXPORT void fromEulerZXZ(const DVect3 &)
Definition: quat.cpp:195
const double & i() const
Access the first imaginary part.
Definition: quat.h:128
const Quat3 & operator*=(const double &d)
In place multiplaction by a double.
Definition: quat.h:217
bool operator==(const Quat3 &v) const
Euality operator.
Definition: quat.h:234
double & rw()
Access a reference to the real part.
Definition: quat.h:135
BASE_EXPORT void spinAboutZ(const double &)
Just spin about the Z axis.
Definition: quat.cpp:217
BASE_EXPORT DVect3 quatToEuler() const
Definition: quat.cpp:273
Quat3 operator/(const double &d) const
Division by a double.
Definition: quat.h:204
BASE_EXPORT void fromMatrix(const DMatrix< 3, 3 > &)
Convert a matrix into a quaternion.
Definition: quat.cpp:128
double & ri()
Access a reference to the first imaginary part.
Definition: quat.h:137
BASE_EXPORT void normalize()
Normalize the quaternion.
Definition: quat.h:199
double & rk()
Access a reference to the third imaginary part.
Definition: quat.h:141
#define BASE_EXPORT
Definition: basedef.h:24
A template-based matrix class, size fixed at compile time.
2D and 3D vector utility classes.