Quaternion.cc File Reference
#include "Math/Quaternion.h"

Functions

std::ostream & operator<< (std::ostream &os, const Quaternion &a)
 
std::istream & operator>> (std::istream &is, Quaternion &a)
 
Quaternion operator+ (const Mdouble a, const Quaternion &b)
 
Quaternion operator- (const Mdouble a, const Quaternion &b)
 
Quaternion operator- (const Quaternion &a)
 
Quaternion operator* (const Mdouble a, const Quaternion &b)
 

Function Documentation

◆ operator*()

Quaternion operator* ( const Mdouble  a,
const Quaternion b 
)

Multiplies each element of a given quaternion (b) by a given scalar (a). NB: this is a global function and a friend of the Quaternion class. Gets called when a scalar multiplication of the form (Mdouble) * (Quaternion) is performed.

Parameters
[in]athe scalar
[in]bthe quaternion
Returns
the resulting quaternion
406 {
407  return Quaternion(b.q0 * a, b.q1 * a, b.q2 * a, b.q3 * a);
408 }
This class contains the 4 components of a quaternion and the standard operators and functions needed ...
Definition: Quaternion.h:63
Mdouble q1
the first component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:73
Mdouble q3
the third component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:81
Mdouble q2
the second component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:77
Mdouble q0
the zeroth component of the quaternion q = (q0,q1,q2,q3)
Definition: Quaternion.h:69

◆ operator+()

Quaternion operator+ ( const Mdouble  a,
const Quaternion b 
)

Adds a scalar to the elements of given quaternion NB this is a global function and a friend of the Quaternion class. Gets called when addition operation of the form (Mdouble) + (Quaternion) is performed.

Parameters
[in]athe scalar to be added
[in]bthe quaternion the scalar gets added to.
Returns
the resulting quaternion.
368 {
369  return Quaternion(b.q0 + a, b.q1 + a, b.q2 + a, b.q3 + a);
370 }

◆ operator-() [1/2]

Quaternion operator- ( const Mdouble  a,
const Quaternion b 
)

Subtracts each element of a given quaternion from a scalar NB this is a global function and a friend of the Quaternion class. Gets called when subtraction operation of the form (Mdouble) - (Quaternion) is performed.

Parameters
[in]athe scalar
[in]bthe quaternion to be subtracted the scalar gets subtracted from.
Returns
the resulting quaternion.
381 {
382  return Quaternion(a - b.q0, a - b.q1, a - b.q2, a - b.q3);
383 }

◆ operator-() [2/2]

Quaternion operator- ( const Quaternion a)

Returns the negative of a given quaternion. NB: this is a global function and a friend of the Quaternion class. Gets called when a negation operation of the form - (Quaternion) is performed.

Parameters
[in]athe quaternion to be negated
Returns
the negated quaternion
393 {
394  return Quaternion(-a.q0, -a.q1, -a.q2, -a.q3);
395 }

◆ operator<<()

std::ostream& operator<< ( std::ostream &  os,
const Quaternion a 
)

Adds all elements of the quaternion to an output stream. NB: this is a global function and a friend of the Quaternion class!

Parameters
[in]osthe output stream,
[in]aThe quaternion of interest
Returns
the output stream with quaternion elements added
341 {
342  os << a.q0 << ' ' << a.q1 << ' ' << a.q2 << ' ' << a.q3;
343  return os;
344 }

◆ operator>>()

std::istream& operator>> ( std::istream &  is,
Quaternion a 
)

Reads all elements of a given quaternion from an input stream. NB: this is a global function and a friend of the Quaternion class!

Parameters
[in,out]isthe input stream
[in,out]athe quaternion to be read in
Returns
the input stream from which the quaternion elements were read
354 {
355  is >> a.q0 >> a.q1 >> a.q2 >> a.q3;
356  return is;
357 }