OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
ossim::Quaternion Class Reference

A quaternion class. More...

#include <ossimQuaternion.h>

Public Types

typedef ossim_float64 value_type
 

Public Member Functions

 Quaternion ()
 
 Quaternion (value_type x, value_type y, value_type z, value_type w)
 
 Quaternion (ossim_float64 angle, const ossimDpt3d &axis)
 
 Quaternion (ossim_float64 angle, const ossimColumnVector3d &axis)
 
Quaternionoperator= (const Quaternion &v)
 
bool operator== (const Quaternion &v) const
 
bool operator!= (const Quaternion &v) const
 
bool operator< (const Quaternion &v) const
 
void set (value_type x, value_type y, value_type z, value_type w)
 
void set (const ossimMatrix4x4 &matrix)
 Good introductions to Quaternions at: http://www.gamasutra.com/features/programming/19980703/quaternions_01.htm http://mathworld.wolfram.com/Quaternion.html. More...
 
void get (ossimMatrix4x4 &matrix) const
 
value_typeoperator[] (int i)
 
value_type operator[] (int i) const
 
value_typex ()
 
value_typey ()
 
value_typez ()
 
value_typew ()
 
value_type x () const
 
value_type y () const
 
value_type z () const
 
value_type w () const
 
bool zeroRotation () const
 return true if the Quaternion represents a zero rotation, and therefore can be ignored in computations. More...
 
const Quaternion operator* (value_type rhs) const
 Multiply by scalar. More...
 
Quaternionoperator*= (value_type rhs)
 Unary multiply by scalar. More...
 
const Quaternion operator* (const Quaternion &rhs) const
 Binary multiply. More...
 
Quaternionoperator*= (const Quaternion &rhs)
 Unary multiply. More...
 
Quaternion operator/ (value_type rhs) const
 Divide by scalar. More...
 
Quaternionoperator/= (value_type rhs)
 Unary divide by scalar. More...
 
const Quaternion operator/ (const Quaternion &denom) const
 Binary divide. More...
 
Quaternionoperator/= (const Quaternion &denom)
 Unary divide. More...
 
const Quaternion operator+ (const Quaternion &rhs) const
 Binary addition. More...
 
Quaternionoperator+= (const Quaternion &rhs)
 Unary addition. More...
 
const Quaternion operator- (const Quaternion &rhs) const
 Binary subtraction. More...
 
Quaternionoperator-= (const Quaternion &rhs)
 Unary subtraction. More...
 
const Quaternion operator- () const
 Negation operator - returns the negative of the quaternion. More...
 
value_type length () const
 Length of the quaternion = sqrt( vec . vec ) More...
 
value_type length2 () const
 Length of the quaternion = vec . vec. More...
 
Quaternion conj () const
 Conjugate. More...
 
const Quaternion inverse () const
 Multiplicative inverse method: q^(-1) = q^*/(q.q^*) More...
 
void makeRotate (value_type angle, value_type x, value_type y, value_type z)
 Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x,y,z) More...
 
void makeRotate (value_type angle, const ossimColumnVector3d &vec)
 
void makeRotate (value_type angle, const ossimDpt3d &vec)
 
void makeRotate (value_type angle1, const ossimColumnVector3d &axis1, value_type angle2, const ossimColumnVector3d &axis2, value_type angle3, const ossimColumnVector3d &axis3)
 
void makeRotate (value_type angle1, const ossimDpt3d &axis1, value_type angle2, const ossimDpt3d &axis2, value_type angle3, const ossimDpt3d &axis3)
 
void makeRotate (const ossimColumnVector3d &vec1, const ossimColumnVector3d &vec2)
 Make a rotation Quaternion which will rotate vec1 to vec2. More...
 
void makeRotate (const ossimDpt3d &vec1, const ossimDpt3d &vec2)
 Make a rotation Quaternion which will rotate vec1 to vec2. More...
 
void getRotate (value_type &angle, value_type &x, value_type &y, value_type &z) const
 Return the angle and vector components represented by the quaternion. More...
 
void getRotate (value_type &angle, ossimDpt3d &vec) const
 Return the angle and vector components represented by the quaternion. More...
 
void slerp (value_type t, const Quaternion &from, const Quaternion &to)
 Spherical Linear Interpolation. More...
 
ossimDpt3d operator* (const ossimDpt3d &v) const
 Rotate a vector by this quaternion. More...
 

Public Attributes

value_type theVector [4]
 

Friends

ossimDpt3d operator* (const ossimDpt3d &lhs, const ossim::Quaternion &rhs)
 

Detailed Description

A quaternion class.

It can be used to represent an orientation in 3D space.

Definition at line 13 of file ossimQuaternion.h.

Member Typedef Documentation

◆ value_type

Definition at line 18 of file ossimQuaternion.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/4]

ossim::Quaternion::Quaternion ( )
inline

Definition at line 22 of file ossimQuaternion.h.

23  {
24  theVector[0]=0.0; theVector[1]=0.0; theVector[2]=0.0; theVector[3]=1.0;
25  }
value_type theVector[4]

◆ Quaternion() [2/4]

ossim::Quaternion::Quaternion ( value_type  x,
value_type  y,
value_type  z,
value_type  w 
)
inline

Definition at line 27 of file ossimQuaternion.h.

References x, and y.

28  {
29  theVector[0]=x;
30  theVector[1]=y;
31  theVector[2]=z;
32  theVector[3]=w;
33  }
value_type & x()
value_type & z()
value_type & w()
value_type & y()
value_type theVector[4]

◆ Quaternion() [3/4]

ossim::Quaternion::Quaternion ( ossim_float64  angle,
const ossimDpt3d axis 
)
inline

Definition at line 51 of file ossimQuaternion.h.

52  {
53  makeRotate(angle,axis);
54  }
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...

◆ Quaternion() [4/4]

ossim::Quaternion::Quaternion ( ossim_float64  angle,
const ossimColumnVector3d axis 
)
inline

Definition at line 55 of file ossimQuaternion.h.

56  {
57  makeRotate(angle,axis);
58  }
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...

Member Function Documentation

◆ conj()

Quaternion ossim::Quaternion::conj ( ) const
inline

Conjugate.

Definition at line 265 of file ossimQuaternion.h.

266  {
267  return Quaternion( -theVector[0], -theVector[1], -theVector[2], theVector[3] );
268  }
value_type theVector[4]

◆ get()

void ossim::Quaternion::get ( ossimMatrix4x4 matrix) const

Definition at line 12 of file ossimQuaternion.cpp.

References ossimMatrix4x4::makeRotate().

13 {
14  matrix.makeRotate(*this);
15 }
void makeRotate(const ossim::Quaternion &quat)

◆ getRotate() [1/2]

void ossim::Quaternion::getRotate ( value_type angle,
value_type x,
value_type y,
value_type z 
) const

Return the angle and vector components represented by the quaternion.

Angle returned is in degrees.

Definition at line 245 of file ossimQuaternion.cpp.

References ossim::radiansToDegrees(), x, and y.

246 {
247  value_type sinhalfangle = sqrt( theVector[0]*theVector[0] + theVector[1]*theVector[1] + theVector[2]*theVector[2] );
248 
249  angle = 2.0 * atan2( sinhalfangle, theVector[3] );
250  if(sinhalfangle)
251  {
252  x = theVector[0] / sinhalfangle;
253  y = theVector[1] / sinhalfangle;
254  z = theVector[2] / sinhalfangle;
255  }
256  else
257  {
258  x = 0.0;
259  y = 0.0;
260  z = 1.0;
261  }
262  angle = ossim::radiansToDegrees(angle);
263 }
value_type & x()
value_type & z()
double radiansToDegrees(double x)
Definition: ossimCommon.h:257
ossim_float64 value_type
value_type & y()
value_type theVector[4]

◆ getRotate() [2/2]

void ossim::Quaternion::getRotate ( value_type angle,
ossimDpt3d vec 
) const
inline

Return the angle and vector components represented by the quaternion.

Angle returned is in degrees.

Definition at line 325 of file ossimQuaternion.h.

References ossimDpt3d::x, ossimDpt3d::y, and ossimDpt3d::z.

326  { getRotate(angle, vec.x, vec.y, vec.z);}
double z
Definition: ossimDpt3d.h:145
void getRotate(value_type &angle, value_type &x, value_type &y, value_type &z) const
Return the angle and vector components represented by the quaternion.
double x
Definition: ossimDpt3d.h:143
double y
Definition: ossimDpt3d.h:144

◆ inverse()

const Quaternion ossim::Quaternion::inverse ( ) const
inline

Multiplicative inverse method: q^(-1) = q^*/(q.q^*)

Definition at line 271 of file ossimQuaternion.h.

Referenced by operator/(), and operator/=().

272  {
273  return conj() / length2();
274  }
Quaternion conj() const
Conjugate.
value_type length2() const
Length of the quaternion = vec . vec.

◆ length()

value_type ossim::Quaternion::length ( ) const
inline

Length of the quaternion = sqrt( vec . vec )

Definition at line 253 of file ossimQuaternion.h.

254  {
255  return std::sqrt( theVector[0]*theVector[0] + theVector[1]*theVector[1] + theVector[2]*theVector[2] + theVector[3]*theVector[3]);
256  }
value_type theVector[4]

◆ length2()

value_type ossim::Quaternion::length2 ( ) const
inline

Length of the quaternion = vec . vec.

Definition at line 259 of file ossimQuaternion.h.

Referenced by ossimMatrix4x4::setRotate().

260  {
261  return theVector[0]*theVector[0] + theVector[1]*theVector[1] + theVector[2]*theVector[2] + theVector[3]*theVector[3];
262  }
value_type theVector[4]

◆ makeRotate() [1/7]

void ossim::Quaternion::makeRotate ( value_type  angle,
value_type  x,
value_type  y,
value_type  z 
)

Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x,y,z)

Definition at line 19 of file ossimQuaternion.cpp.

References ossim::degreesToRadians(), x, and y.

Referenced by makeRotate().

20 {
21 
22  const value_type epsilon = 0.0000001;
23 
24  value_type length = sqrt( x*x + y*y + z*z );
25  if (length < epsilon)
26  {
27  // ~zero length axis, so reset rotation to zero.
28  *this = ossim::Quaternion();
29  return;
30  }
31  double tempAngle = ossim::degreesToRadians(angle);
32 
33  value_type inversenorm = 1.0/length;
34  value_type coshalfangle = cos( 0.5*tempAngle );
35  value_type sinhalfangle = sin( 0.5*tempAngle );
36 
37  theVector[0] = x * sinhalfangle * inversenorm;
38  theVector[1] = y * sinhalfangle * inversenorm;
39  theVector[2] = z * sinhalfangle * inversenorm;
40  theVector[3] = coshalfangle;
41 }
value_type & x()
value_type length() const
Length of the quaternion = sqrt( vec . vec )
A quaternion class.
value_type & z()
double degreesToRadians(double x)
Definition: ossimCommon.h:258
ossim_float64 value_type
value_type & y()
value_type theVector[4]

◆ makeRotate() [2/7]

void ossim::Quaternion::makeRotate ( value_type  angle,
const ossimColumnVector3d vec 
)
inline

Definition at line 288 of file ossimQuaternion.h.

289  { makeRotate(angle, vec[0], vec[1], vec[2]);}
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...

◆ makeRotate() [3/7]

void ossim::Quaternion::makeRotate ( value_type  angle,
const ossimDpt3d vec 
)
inline

Definition at line 290 of file ossimQuaternion.h.

References ossimDpt3d::x, ossimDpt3d::y, and ossimDpt3d::z.

291  { makeRotate(angle, vec.x, vec.y, vec.z);}
double z
Definition: ossimDpt3d.h:145
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...
double x
Definition: ossimDpt3d.h:143
double y
Definition: ossimDpt3d.h:144

◆ makeRotate() [4/7]

void ossim::Quaternion::makeRotate ( value_type  angle1,
const ossimColumnVector3d axis1,
value_type  angle2,
const ossimColumnVector3d axis2,
value_type  angle3,
const ossimColumnVector3d axis3 
)

Definition at line 43 of file ossimQuaternion.cpp.

References makeRotate().

46 {
47  ossim::Quaternion q1; q1.makeRotate(angle1,axis1);
48  ossim::Quaternion q2; q2.makeRotate(angle2,axis2);
49  ossim::Quaternion q3; q3.makeRotate(angle3,axis3);
50  *this = q1*q2*q3;
51 }
A quaternion class.
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...

◆ makeRotate() [5/7]

void ossim::Quaternion::makeRotate ( value_type  angle1,
const ossimDpt3d axis1,
value_type  angle2,
const ossimDpt3d axis2,
value_type  angle3,
const ossimDpt3d axis3 
)

Definition at line 53 of file ossimQuaternion.cpp.

References makeRotate().

56 {
57  ossim::Quaternion q1; q1.makeRotate(angle1,axis1);
58  ossim::Quaternion q2; q2.makeRotate(angle2,axis2);
59  ossim::Quaternion q3; q3.makeRotate(angle3,axis3);
60 
61  *this = q1*q2*q3;
62 }
A quaternion class.
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...

◆ makeRotate() [6/7]

void ossim::Quaternion::makeRotate ( const ossimColumnVector3d vec1,
const ossimColumnVector3d vec2 
)

Make a rotation Quaternion which will rotate vec1 to vec2.

Generally take a dot product to get the angle between these and then use a cross product to get the rotation axis Watch out for the two special cases when the vectors are co-incident or opposite in direction.

Definition at line 64 of file ossimQuaternion.cpp.

65 {
66  makeRotate(ossimDpt3d(vec1[0], vec1[1], vec1[2]),
67  ossimDpt3d(vec2[0], vec2[1], vec2[2]));
68 }
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...

◆ makeRotate() [7/7]

void ossim::Quaternion::makeRotate ( const ossimDpt3d from,
const ossimDpt3d to 
)

Make a rotation Quaternion which will rotate vec1 to vec2.

Make a rotation Quat which will rotate vec1 to vec2.

Generally take a dot product to get the angle between these and then use a cross product to get the rotation axis Watch out for the two special cases of when the vectors are co-incident or opposite in direction.

This routine uses only fast geometric transforms, without costly acos/sin computations. It's exact, fast, and with less degenerate cases than the acos/sin method.

For an explanation of the math used, you may see for example: http://logiciels.cnes.fr/MARMOTTES/marmottes-mathematique.pdf

Note
This is the rotation with shortest angle, which is the one equivalent to the acos/sin transform method. Other rotations exists, for example to additionally keep a local horizontal attitude.
Author
Nicolas Brodu

Definition at line 85 of file ossimQuaternion.cpp.

References ossimDpt3d::length2(), ossimDpt3d::x, ossimDpt3d::y, and ossimDpt3d::z.

86 {
87 
88  // This routine takes any vector as argument but normalized
89  // vectors are necessary, if only for computing the dot product.
90  // Too bad the API is that generic, it leads to performance loss.
91  // Even in the case the 2 vectors are not normalized but same length,
92  // the sqrt could be shared, but we have no way to know beforehand
93  // at this point, while the caller may know.
94  // So, we have to test... in the hope of saving at least a sqrt
95  ossimDpt3d sourceVector = from;
96  ossimDpt3d targetVector = to;
97 
98  value_type fromLen2 = from.length2();
99  value_type fromLen = 1.0;
100  // normalize only when necessary, epsilon test
101  if ((fromLen2 < 1.0-1e-7) || (fromLen2 > 1.0+1e-7))
102  {
103  fromLen = sqrt(fromLen2);
104  sourceVector /= fromLen;
105  }
106 
107  value_type toLen2 = to.length2();
108  // normalize only when necessary, epsilon test
109  if ((toLen2 < 1.0-1e-7) || (toLen2 > 1.0+1e-7))
110  {
111  value_type toLen;
112  // re-use fromLen for case of mapping 2 vectors of the same length
113  if ((toLen2 > fromLen2-1e-7) && (toLen2 < fromLen2+1e-7))
114  {
115  toLen = fromLen;
116  }
117  else toLen = sqrt(toLen2);
118  targetVector /= toLen;
119  }
120 
121  // Now let's get into the real stuff
122  // Use "dot product plus one" as test as it can be re-used later on
123  double dotProdPlus1 = 1.0 + sourceVector * targetVector;
124 
125  // Check for degenerate case of full u-turn. Use epsilon for detection
126  if (dotProdPlus1 < 1e-7) {
127 
128  // Get an orthogonal vector of the given vector
129  // in a plane with maximum vector coordinates.
130  // Then use it as quaternion axis with pi angle
131  // Trick is to realize one value at least is >0.6 for a normalized vector.
132  if (fabs(sourceVector.x) < 0.6) {
133  const double norm = sqrt(1.0 - sourceVector.x * sourceVector.x);
134  theVector[0] = 0.0;
135  theVector[1] = sourceVector.z / norm;
136  theVector[2] = -sourceVector.y / norm;
137  theVector[3] = 0.0;
138  } else if (fabs(sourceVector.y) < 0.6) {
139  const double norm = sqrt(1.0 - sourceVector.y * sourceVector.y);
140  theVector[0] = -sourceVector.z / norm;
141  theVector[1] = 0.0;
142  theVector[2] = sourceVector.x / norm;
143  theVector[3] = 0.0;
144  } else {
145  const double norm = sqrt(1.0 - sourceVector.z * sourceVector.z);
146  theVector[0] = sourceVector.y / norm;
147  theVector[1] = -sourceVector.x / norm;
148  theVector[2] = 0.0;
149  theVector[3] = 0.0;
150  }
151  }
152 
153  else {
154  // Find the shortest angle quaternion that transforms normalized vectors
155  // into one other. Formula is still valid when vectors are colinear
156  const double s = sqrt(0.5 * dotProdPlus1);
157  const ossimDpt3d tmp = sourceVector ^ targetVector / (2.0*s);
158  theVector[0] = tmp.x;
159  theVector[1] = tmp.y;
160  theVector[2] = tmp.z;
161  theVector[3] = s;
162  }
163 }
double length2() const
Definition: ossimDpt3d.h:72
double z
Definition: ossimDpt3d.h:145
ossim_float64 value_type
double x
Definition: ossimDpt3d.h:143
double y
Definition: ossimDpt3d.h:144
value_type theVector[4]

◆ operator!=()

bool ossim::Quaternion::operator!= ( const Quaternion v) const
inline

Definition at line 89 of file ossimQuaternion.h.

References theVector.

89 { return theVector[0]!=v.theVector[0] || theVector[1]!=v.theVector[1] || theVector[2]!=v.theVector[2] || theVector[3]!=v.theVector[3]; }
value_type theVector[4]

◆ operator*() [1/3]

const Quaternion ossim::Quaternion::operator* ( value_type  rhs) const
inline

Multiply by scalar.

Definition at line 141 of file ossimQuaternion.h.

142  {
143  return Quaternion(theVector[0]*rhs, theVector[1]*rhs, theVector[2]*rhs, theVector[3]*rhs);
144  }
value_type theVector[4]

◆ operator*() [2/3]

const Quaternion ossim::Quaternion::operator* ( const Quaternion rhs) const
inline

Binary multiply.

Definition at line 157 of file ossimQuaternion.h.

References theVector.

158  {
159  return Quaternion( rhs.theVector[3]*theVector[0] + rhs.theVector[0]*theVector[3] + rhs.theVector[1]*theVector[2] - rhs.theVector[2]*theVector[1],
160  rhs.theVector[3]*theVector[1] - rhs.theVector[0]*theVector[2] + rhs.theVector[1]*theVector[3] + rhs.theVector[2]*theVector[0],
161  rhs.theVector[3]*theVector[2] + rhs.theVector[0]*theVector[1] - rhs.theVector[1]*theVector[0] + rhs.theVector[2]*theVector[3],
162  rhs.theVector[3]*theVector[3] - rhs.theVector[0]*theVector[0] - rhs.theVector[1]*theVector[1] - rhs.theVector[2]*theVector[2] );
163  }
value_type theVector[4]

◆ operator*() [3/3]

ossimDpt3d ossim::Quaternion::operator* ( const ossimDpt3d v) const
inline

Rotate a vector by this quaternion.

Definition at line 333 of file ossimQuaternion.h.

334  {
335  // nVidia SDK implementation
336  ossimDpt3d uv, uuv;
337  ossimDpt3d qvec(theVector[0], theVector[1], theVector[2]);
338  uv = qvec ^ v;
339  uuv = qvec ^ uv;
340  uv *= ( 2.0f * theVector[3] );
341  uuv *= 2.0f;
342  return v + uv + uuv;
343  }
value_type theVector[4]

◆ operator*=() [1/2]

Quaternion& ossim::Quaternion::operator*= ( value_type  rhs)
inline

Unary multiply by scalar.

Definition at line 147 of file ossimQuaternion.h.

148  {
149  theVector[0]*=rhs;
150  theVector[1]*=rhs;
151  theVector[2]*=rhs;
152  theVector[3]*=rhs;
153  return *this; // enable nesting
154  }
value_type theVector[4]

◆ operator*=() [2/2]

Quaternion& ossim::Quaternion::operator*= ( const Quaternion rhs)
inline

Unary multiply.

Definition at line 166 of file ossimQuaternion.h.

References theVector, x, and y.

167  {
168  value_type x = rhs.theVector[3]*theVector[0] + rhs.theVector[0]*theVector[3] + rhs.theVector[1]*theVector[2] - rhs.theVector[2]*theVector[1];
169  value_type y = rhs.theVector[3]*theVector[1] - rhs.theVector[0]*theVector[2] + rhs.theVector[1]*theVector[3] + rhs.theVector[2]*theVector[0];
170  value_type z = rhs.theVector[3]*theVector[2] + rhs.theVector[0]*theVector[1] - rhs.theVector[1]*theVector[0] + rhs.theVector[2]*theVector[3];
171  theVector[3] = rhs.theVector[3]*theVector[3] - rhs.theVector[0]*theVector[0] - rhs.theVector[1]*theVector[1] - rhs.theVector[2]*theVector[2];
172 
173  theVector[2] = z;
174  theVector[1] = y;
175  theVector[0] = x;
176 
177  return (*this); // enable nesting
178  }
value_type & x()
value_type & z()
ossim_float64 value_type
value_type & y()
value_type theVector[4]

◆ operator+()

const Quaternion ossim::Quaternion::operator+ ( const Quaternion rhs) const
inline

Binary addition.

Definition at line 212 of file ossimQuaternion.h.

References theVector.

213  {
214  return Quaternion(theVector[0]+rhs.theVector[0], theVector[1]+rhs.theVector[1],
215  theVector[2]+rhs.theVector[2], theVector[3]+rhs.theVector[3]);
216  }
value_type theVector[4]

◆ operator+=()

Quaternion& ossim::Quaternion::operator+= ( const Quaternion rhs)
inline

Unary addition.

Definition at line 219 of file ossimQuaternion.h.

References theVector.

220  {
221  theVector[0] += rhs.theVector[0];
222  theVector[1] += rhs.theVector[1];
223  theVector[2] += rhs.theVector[2];
224  theVector[3] += rhs.theVector[3];
225  return *this; // enable nesting
226  }
value_type theVector[4]

◆ operator-() [1/2]

const Quaternion ossim::Quaternion::operator- ( const Quaternion rhs) const
inline

Binary subtraction.

Definition at line 229 of file ossimQuaternion.h.

References theVector.

230  {
231  return Quaternion(theVector[0]-rhs.theVector[0], theVector[1]-rhs.theVector[1],
232  theVector[2]-rhs.theVector[2], theVector[3]-rhs.theVector[3] );
233  }
value_type theVector[4]

◆ operator-() [2/2]

const Quaternion ossim::Quaternion::operator- ( ) const
inline

Negation operator - returns the negative of the quaternion.

Basically just calls operator - () on the Vec4

Definition at line 247 of file ossimQuaternion.h.

248  {
249  return Quaternion (-theVector[0], -theVector[1], -theVector[2], -theVector[3]);
250  }
value_type theVector[4]

◆ operator-=()

Quaternion& ossim::Quaternion::operator-= ( const Quaternion rhs)
inline

Unary subtraction.

Definition at line 236 of file ossimQuaternion.h.

References theVector.

237  {
238  theVector[0]-=rhs.theVector[0];
239  theVector[1]-=rhs.theVector[1];
240  theVector[2]-=rhs.theVector[2];
241  theVector[3]-=rhs.theVector[3];
242  return *this; // enable nesting
243  }
value_type theVector[4]

◆ operator/() [1/2]

Quaternion ossim::Quaternion::operator/ ( value_type  rhs) const
inline

Divide by scalar.

Definition at line 181 of file ossimQuaternion.h.

182  {
183  value_type div = 1.0/rhs;
184  return Quaternion(theVector[0]*div, theVector[1]*div, theVector[2]*div, theVector[3]*div);
185  }
ossim_float64 value_type
value_type theVector[4]

◆ operator/() [2/2]

const Quaternion ossim::Quaternion::operator/ ( const Quaternion denom) const
inline

Binary divide.

Definition at line 199 of file ossimQuaternion.h.

References inverse().

200  {
201  return ( (*this) * denom.inverse() );
202  }

◆ operator/=() [1/2]

Quaternion& ossim::Quaternion::operator/= ( value_type  rhs)
inline

Unary divide by scalar.

Definition at line 188 of file ossimQuaternion.h.

189  {
190  value_type div = 1.0/rhs;
191  theVector[0]*=div;
192  theVector[1]*=div;
193  theVector[2]*=div;
194  theVector[3]*=div;
195  return *this;
196  }
ossim_float64 value_type
value_type theVector[4]

◆ operator/=() [2/2]

Quaternion& ossim::Quaternion::operator/= ( const Quaternion denom)
inline

Unary divide.

Definition at line 205 of file ossimQuaternion.h.

References inverse().

206  {
207  (*this) = (*this) * denom.inverse();
208  return (*this); // enable nesting
209  }

◆ operator<()

bool ossim::Quaternion::operator< ( const Quaternion v) const
inline

Definition at line 91 of file ossimQuaternion.h.

References theVector.

92  {
93  if (theVector[0]<v.theVector[0]) return true;
94  else if (theVector[0]>v.theVector[0]) return false;
95  else if (theVector[1]<v.theVector[1]) return true;
96  else if (theVector[1]>v.theVector[1]) return false;
97  else if (theVector[2]<v.theVector[2]) return true;
98  else if (theVector[2]>v.theVector[2]) return false;
99  else return (theVector[3]<v.theVector[3]);
100  }
value_type theVector[4]

◆ operator=()

Quaternion& ossim::Quaternion::operator= ( const Quaternion v)
inline

Definition at line 78 of file ossimQuaternion.h.

References theVector.

79  {
80  theVector[0]=v.theVector[0];
81  theVector[1]=v.theVector[1];
82  theVector[2]=v.theVector[2];
83  theVector[3]=v.theVector[3];
84  return *this;
85  }
value_type theVector[4]

◆ operator==()

bool ossim::Quaternion::operator== ( const Quaternion v) const
inline

Definition at line 87 of file ossimQuaternion.h.

References theVector.

87 { return theVector[0]==v.theVector[0] && theVector[1]==v.theVector[1] && theVector[2]==v.theVector[2] && theVector[3]==v.theVector[3]; }
value_type theVector[4]

◆ operator[]() [1/2]

value_type& ossim::Quaternion::operator[] ( int  i)
inline

Definition at line 116 of file ossimQuaternion.h.

116 { return theVector[i]; }
value_type theVector[4]

◆ operator[]() [2/2]

value_type ossim::Quaternion::operator[] ( int  i) const
inline

Definition at line 117 of file ossimQuaternion.h.

117 { return theVector[i]; }
value_type theVector[4]

◆ set() [1/2]

void ossim::Quaternion::set ( value_type  x,
value_type  y,
value_type  z,
value_type  w 
)
inline

Definition at line 103 of file ossimQuaternion.h.

References x, and y.

104  {
105  theVector[0]=x;
106  theVector[1]=y;
107  theVector[2]=z;
108  theVector[3]=w;
109  }
value_type & x()
value_type & z()
value_type & w()
value_type & y()
value_type theVector[4]

◆ set() [2/2]

void ossim::Quaternion::set ( const ossimMatrix4x4 matrix)

Good introductions to Quaternions at: http://www.gamasutra.com/features/programming/19980703/quaternions_01.htm http://mathworld.wolfram.com/Quaternion.html.

Definition at line 7 of file ossimQuaternion.cpp.

References ossimMatrix4x4::getRotate().

8 {
9  matrix.getRotate(*this);
10 }
ossim::Quaternion getRotate() const

◆ slerp()

void ossim::Quaternion::slerp ( value_type  t,
const Quaternion from,
const Quaternion to 
)

Spherical Linear Interpolation.

As it goes from 0 to 1, the Quaternion object goes from "from" to "to".

◆ w() [1/2]

value_type& ossim::Quaternion::w ( )
inline

Definition at line 122 of file ossimQuaternion.h.

122 { return theVector[3]; }
value_type theVector[4]

◆ w() [2/2]

value_type ossim::Quaternion::w ( ) const
inline

Definition at line 127 of file ossimQuaternion.h.

127 { return theVector[3]; }
value_type theVector[4]

◆ x() [1/2]

value_type& ossim::Quaternion::x ( )
inline

Definition at line 119 of file ossimQuaternion.h.

119 { return theVector[0]; }
value_type theVector[4]

◆ x() [2/2]

value_type ossim::Quaternion::x ( ) const
inline

Definition at line 124 of file ossimQuaternion.h.

124 { return theVector[0]; }
value_type theVector[4]

◆ y() [1/2]

value_type& ossim::Quaternion::y ( )
inline

Definition at line 120 of file ossimQuaternion.h.

120 { return theVector[1]; }
value_type theVector[4]

◆ y() [2/2]

value_type ossim::Quaternion::y ( ) const
inline

Definition at line 125 of file ossimQuaternion.h.

125 { return theVector[1]; }
value_type theVector[4]

◆ z() [1/2]

value_type& ossim::Quaternion::z ( )
inline

Definition at line 121 of file ossimQuaternion.h.

121 { return theVector[2]; }
value_type theVector[4]

◆ z() [2/2]

value_type ossim::Quaternion::z ( ) const
inline

Definition at line 126 of file ossimQuaternion.h.

126 { return theVector[2]; }
value_type theVector[4]

◆ zeroRotation()

bool ossim::Quaternion::zeroRotation ( ) const
inline

return true if the Quaternion represents a zero rotation, and therefore can be ignored in computations.

Definition at line 130 of file ossimQuaternion.h.

130 { return theVector[0]==0.0 && theVector[1]==0.0 && theVector[2]==0.0 && theVector[3]==1.0; }
value_type theVector[4]

Friends And Related Function Documentation

◆ operator*

ossimDpt3d operator* ( const ossimDpt3d lhs,
const ossim::Quaternion rhs 
)
friend

Definition at line 344 of file ossimQuaternion.h.

345  {
346  ossimDpt3d uv, uuv;
347  ossimDpt3d qvec(rhs.theVector[0], rhs.theVector[1], rhs.theVector[2]);
348  uv = qvec ^ lhs;
349  uuv = qvec ^ uv;
350  uv *= ( 2.0f * rhs.theVector[3] );
351  uuv *= 2.0f;
352 
353  return lhs + uv + uuv;
354  }
value_type theVector[4]

Member Data Documentation

◆ theVector

value_type ossim::Quaternion::theVector[4]

The documentation for this class was generated from the following files: