MathToolKit  1.1.1
C++ maths framework
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Vector3 Class Reference

Class representing 3D Euclidean space. More...

Inheritance diagram for Vector3:
NVector< double_t >

Public Member Functions

 Vector3 (double_t x=0, double_t y=0, double_t z=0)
 
double_t x () const
 
double_t y () const
 
double_t z () const
 
double_t r () const
 
double_t theta () const
 
double_t phi () const
 
Vector3 rXY () const
 
void setX (double_t scalar)
 
void setY (double_t scalar)
 
void setZ (double_t scalar)
 
void setR (double_t scalar)
 
void setTheta (double_t scalar)
 
void setPhi (double_t scalar)
 
void setXYZ (double_t x, double_t y, double_t z)
 
void setRThetaZ (double_t r, double_t theta, double_t z)
 
void setRThetaPhi (double_t r, double_t theta, double_t phi)
 
Vector3operator^= (const Vector3 &u)
 
- Public Member Functions inherited from NVector< double_t >
 NVector (const std::vector< double_t > &data)
 Construct a vector using a std::vector. \( x_k \) represents data[k]. More...
 
 NVector (std::initializer_list< double_t > list)
 Construct a vector using an initializer list {}. More...
 
 NVector (size_t dim=0)
 Construct a vector of a given size. More...
 
 NVector (const NVector< double_t > &u)
 Construct a vector by using copy() method. More...
 
virtual ~NVector ()=default
 
virtual std::string str () const
 Creates a string representing the vector. More...
 
size_t dim () const
 Dimension of the vector. More...
 
std::vector< double_t > array () const
 Creates an array with this vector. More...
 
NVector< double_t > & operator+= (const NVector< double_t > &u)
 
NVector< double_t > & operator-= (const NVector< double_t > &u)
 
virtual NVector< double_t > & operator*= (double_ts)
 
virtual NVector< double_t > & operator/= (double_ts)
 
NVector< double_t > & operator= (const NVector< double_t > &u)
 Copy source object on this object using copy(). More...
 
double_t max () const
 Maximum of the coordinates of the vector \( (x_0, x_1, .. x_{(n-1)}) \). More...
 
double_t min () const
 Minimum of the coordinates of the vector \( (x_0, x_1, .. x_{(n-1)}) \). More...
 
size_t maxIndex () const
 Index of maximum of the coordinates of vector \( (x_0, x_1, ..., x_{(n-1)}) \). More...
 
size_t minIndex () const
 Index of minimum of the coordinates of vector \( (x_0, x_1, ..., x_{(n-1)}) \). More...
 
double_t maxAbs () const
 Maximum of the coordinates of the vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More...
 
double_t minAbs () const
 Minimum of the coordinates of the vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More...
 
size_t maxAbsIndex () const
 Index of maximum of the coordinates of vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More...
 
size_t minAbsIndex () const
 Index of minimum of the coordinates of vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More...
 
NVector< double_t > & swap (size_t k1, size_t k2)
 Permutation of two elements. More...
 
NVector< double_t > & shift (long iterations)
 Shifts this vector iterations times. More...
 
NVector< double_t > & fill (double_ts)
 Fill vector with a scalar. For example fill(3) will set \( (3, 3, 3, ..., 3) \). More...
 
double_t & operator() (long k)
 Simple access operator. More...
 
double_t operator() (long k) const
 
NVector< double_t > operator() (size_t k1, size_t k2) const
 Manipulate sub-vector. More...
 
NVector< double_t > & operator() (size_t k1, size_t k2)
 Manipulate sub-vector. More...
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 

Static Public Member Functions

static Vector3 zeros ()
 
static Vector3 ones ()
 
static Vector3 scalar (double_t scalar)
 
static Vector3 cano (size_t k)
 
- Static Public Member Functions inherited from NVector< double_t >
static NVector< double_t > zeros (size_t dim)
 
static NVector< double_t > ones (size_t dim)
 
static NVector< double_t > scalar (double_ts, size_t dim)
 
static NVector< double_t > cano (size_t k, size_t dim)
 
static NVector< double_t > sum (const std::vector< NVector > &vectors)
 Sum of multiples vectors. More...
 
static NVector< double_t > sumProd (const std::vector< double_t > &scalars, const std::vector< NVector > &vectors)
 Linear combination of scalars and vectors. More...
 

Protected Member Functions

Vector3cross (const Vector3 &u)
 
double_t angle (const Vector3 &u) const
 
double_t pCos (const Vector3 &u) const
 
double_t pSin (const Vector3 &u) const
 
double_t pTan (const Vector3 &u) const
 
- Protected Member Functions inherited from NVector< double_t >
 NVector (const std::vector< double_t > &data, size_t k1, size_t k2)
 Vector with regularly spaced components. More...
 
NVector< double_t > & add (const NVector< double_t > &u)
 
NVector< double_t > & sub (const NVector< double_t > &u)
 
virtual NVector< double_t > & opp ()
 
virtual NVector< double_t > & prod (double_ts)
 
virtual NVector< double_t > & div (double_ts)
 
double_t dotProduct (const NVector< double_t > &u) const
 
double_t distance (const NVector< double_t > &u) const
 
bool isValidIndex (size_t k) const
 
bool isBetweenK12 (size_t k) const
 
bool isNull () const
 
bool isEqual (const NVector< double_t > &u) const
 
bool hasSameSize (const NVector< double_t > &u) const
 
virtual bool hasDefaultBrowseIndices () const
 
virtual void setDefaultBrowseIndices () const
 
NVector< double_t > & forEach (const NVector< double_t > &u, const std::function< void(double_t &, const double_t &)> &binary_op)
 
virtual NVector< double_t > & forEach (double_ts, const std::function< void(double_t &, double_t)> &binary_op)
 
NVector< double_t > & copy (const NVector< double_t > &u)
 
NVector< double_t > subVector (size_t k1, size_t k2) const
 
void setSubVector (const NVector< double_t > &u)
 
double_t norm () const
 

Friends

Vector3 operator+ (Vector3 u, const Vector3 &v)
 
Vector3 operator- (Vector3 u, const Vector3 &v)
 
Vector3 operator- (Vector3 u)
 
Vector3 operator* (double_t s, Vector3 u)
 
Vector3 operator* (const Vector3 &u, double_t s)
 
Vector3 operator/ (Vector3 u, double_t s)
 
double_t operator| (const Vector3 &u, const Vector3 &v)
 
double_t operator! (const Vector3 &u)
 
double_t operator/ (const Vector3 &u, const Vector3 &v)
 
Vector3 operator^ (Vector3 u, const Vector3 &v)
 Vector product between two us. More...
 
double_t operator% (const Vector3 &u, const Vector3 &v)
 Angle between two us. More...
 

Additional Inherited Members

- Protected Attributes inherited from NVector< double_t >
size_t _k1
 
size_t _k2
 

Detailed Description

Class representing 3D Euclidean space.

Date
04/05/2018
Author
samiBendou

Featuring cross product, coordinate transforms and rotations. We will use the following 3D systems of coordinates :

       -  \form#114 Cartesian coordinates.

       -  \form#115 Cylindrical coordinates. We have the following transformations :

\[ \begin{align*} & r_{xy} & = & \sqrt{x^2 + y^2} \\ & \theta & = & atan(y / x) \\ & z & = & z \\ \end{align*} \]

      -  \form#117 Spherical coordinates. We have the following transformations :

\[ \begin{align*} & r & = & \sqrt{x^2 + y^2 + z^2} \\ & \theta & = & atan(y / x) \\ & \phi & = & atan(r_{xy} / z) \\ \end{align*} \]

      The u is stored in cartesian coordinates. Getting and
      setting components generally implies a constant time calculation to translate between cartesian
      and other formats.

      The `Vector3` class doesn't support function operator `NVector::operator()()`.

Constructor & Destructor Documentation

Vector3::Vector3 ( double_t  x = 0,
double_t  y = 0,
double_t  z = 0 
)
inlineexplicit

Member Function Documentation

double_t Vector3::x ( ) const
inline
double_t Vector3::y ( ) const
inline
double_t Vector3::z ( ) const
inline
double_t Vector3::r ( ) const
inline
double_t Vector3::theta ( ) const
inline
double_t Vector3::phi ( ) const
inline
Vector3 Vector3::rXY ( ) const
inline
void Vector3::setX ( double_t  scalar)
inline
void Vector3::setY ( double_t  scalar)
inline
void Vector3::setZ ( double_t  scalar)
inline
void Vector3::setR ( double_t  scalar)
inline
void Vector3::setTheta ( double_t  scalar)
inline
void Vector3::setPhi ( double_t  scalar)
inline
void Vector3::setXYZ ( double_t  x,
double_t  y,
double_t  z 
)
inline
void Vector3::setRThetaZ ( double_t  r,
double_t  theta,
double_t  z 
)
inline
void Vector3::setRThetaPhi ( double_t  r,
double_t  theta,
double_t  phi 
)
inline
Vector3& Vector3::operator^= ( const Vector3 u)
inline
static Vector3 Vector3::zeros ( )
inlinestatic
static Vector3 Vector3::ones ( )
inlinestatic
static Vector3 Vector3::scalar ( double_t  scalar)
inlinestatic
static Vector3 Vector3::cano ( size_t  k)
inlinestatic
Vector3& Vector3::cross ( const Vector3 u)
inlineprotected
double_t Vector3::angle ( const Vector3 u) const
inlineprotected
double_t Vector3::pCos ( const Vector3 u) const
inlineprotected
double_t Vector3::pSin ( const Vector3 u) const
inlineprotected
double_t Vector3::pTan ( const Vector3 u) const
inlineprotected

Friends And Related Function Documentation

Vector3 operator+ ( Vector3  u,
const Vector3 v 
)
friend
Vector3 operator- ( Vector3  u,
const Vector3 v 
)
friend
Vector3 operator- ( Vector3  u)
friend
Vector3 operator* ( double_t  s,
Vector3  u 
)
friend
Vector3 operator* ( const Vector3 u,
double_t  s 
)
friend
Vector3 operator/ ( Vector3  u,
double_t  s 
)
friend
double_t operator| ( const Vector3 u,
const Vector3 v 
)
friend
double_t operator! ( const Vector3 u)
friend
double_t operator/ ( const Vector3 u,
const Vector3 v 
)
friend
Vector3 operator^ ( Vector3  u,
const Vector3 v 
)
friend

Vector product between two us.

usual u product given by :

\[ \begin{align*} & u_y v_z - u_z v_y \\ & u_z v_x - u_x v_z \\ & u_x v_y - u_y v_x \\ \end{align*} \]

Returns
value of \( \vec{u} \times \vec{v} \).
double_t operator% ( const Vector3 u,
const Vector3 v 
)
friend

Angle between two us.

Returns
value of the angle.