Quaternion.cc File Reference
#include "Math/Quaternion.h"
#include "ExtendedMath.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
387 {
388  return Quaternion(b.q0 * a, b.q1 * a, b.q2 * a, b.q3 * a);
389 }
Scalar * b
Definition: benchVecAdd.cpp:17
This class contains the 4 components of a quaternion and the standard operators and functions needed ...
Definition: Kernel/Math/Quaternion.h:42
const Scalar * a
Definition: level2_cplx_impl.h:32

◆ 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.
349 {
350  return Quaternion(b.q0 + a, b.q1 + a, b.q2 + a, b.q3 + a);
351 }

◆ 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.
362 {
363  return Quaternion(a - b.q0, a - b.q1, a - b.q2, a - b.q3);
364 }

◆ 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
374 {
375  return Quaternion(-a.q0, -a.q1, -a.q2, -a.q3);
376 }

◆ 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
322 {
323  os << a.q0 << ' ' << a.q1 << ' ' << a.q2 << ' ' << a.q3;
324  return os;
325 }

◆ 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
335 {
336  is >> a.q0 >> a.q1 >> a.q2 >> a.q3;
337  return is;
338 }