Workspace 6.21.5
Public Types | Public Member Functions | Public Attributes | Related Functions | List of all members
Vector3d Class Reference

A vector or 3D point in space with useful operation support. More...

#include <Mesh/Geometry/vector3d.h>

Public Types

enum  Axis { AxisX , AxisY , AxisZ }
 

Public Member Functions

 Vector3d ()
 Create a zero vector.
 
 Vector3d (const double *v)
 
 Vector3d (const std::vector< double > &v)
 
 Vector3d (const Vector3d &v)=default
 Create a copy of a vector.
 
 Vector3d (double X, double Y, double Z)
 Create a vector with specific co-ordinates.
 
bool isNanVector () const
 Check whether coords are valid numbers.
 
bool isZeroVector () const
 
bool IsZeroVector () const
 
double magnitude () const
 
double magnitude_2 () const
 
Vector3doperator*= (double d)
 
Vector3doperator+= (const Vector3d &v)
 
Vector3doperator-= (const Vector3d &v)
 
Vector3doperator/= (double d)
 
Vector3doperator= (const Vector3d &v)=default
 
double & operator[] (int i)
 
double operator[] (int i) const
 
void scaleToUnitVector ()
 
void ScaleToUnitVector ()
 
void setToZero ()
 Set all three components of the vector to zero.
 
void SetToZero ()
 
Vector3d unitVector () const
 
Vector3d UnitVector () const
 
Vector3d vectorProjection (const Vector3d &v)
 

Public Attributes

double x
 X co-ordinate.
 
double y
 Y co-ordinate.
 
double z
 Z co-ordinate.
 

Related Functions

(Note that these are not member functions.)

double cosAngle (const Vector3d &t1, const Vector3d &t2)
 
Vector3d crossProduct (const Vector3d &t1, const Vector3d &t2)
 
double dotProduct (const Vector3d &t1, const Vector3d &t2)
 
double magnitude (const Vector3d &v)
 Convenience function - simply calls v.magnitude().
 
double magnitude_2 (const Vector3d &v)
 Convenience function - simply calls v.magnitude_2().
 
bool operator!= (const Vector3d &v0, const Vector3d &v1)
 Non-equivalence.
 
Vector3d operator* (const Vector3d &t, double d)
 Multiplication by a scalar.
 
Vector3d operator* (double d, const Vector3d &t)
 Multiplication by a scalar.
 
Vector3d operator+ (const Vector3d &t1, const Vector3d &t2)
 Addition.
 
Vector3d operator- (const Vector3d &t1)
 Negation.
 
Vector3d operator- (const Vector3d &t1, const Vector3d &t2)
 Subtraction.
 
Vector3d operator/ (const Vector3d &t, double d)
 Division.
 
bool operator== (const Vector3d &v0, const Vector3d &v1)
 Equivalence.
 
double scalarTripleProduct (const Vector3d &t1, const Vector3d &t2, const Vector3d &t3)
 
double sinAngle (const Vector3d &t1, const Vector3d &t2)
 
Vector3d unitVector (const Vector3d &v)
 Convenience function - simply calls v.unitVector().
 

Detailed Description

Common vector operations are defined, such as addition, multiplication, etc. There are also dot and cross product functions. All functions are inlined for maximum performance.

Member Enumeration Documentation

◆ Axis

enum Axis
Enumerator
AxisX 
AxisY 
AxisZ 

Constructor & Destructor Documentation

◆ Vector3d() [1/5]

Vector3d ( )
inline

◆ Vector3d() [2/5]

Vector3d ( double  X,
double  Y,
double  Z 
)
inline

◆ Vector3d() [3/5]

Vector3d ( const Vector3d v)
default

◆ Vector3d() [4/5]

Vector3d ( const double *  v)
inline

◆ Vector3d() [5/5]

Vector3d ( const std::vector< double > &  v)
inline

Member Function Documentation

◆ isNanVector()

bool isNanVector ( ) const
inline

◆ isZeroVector()

bool isZeroVector ( ) const
inline
Returns
True if all three components of the vector are exactly zero.

◆ IsZeroVector()

bool IsZeroVector ( ) const
inline

◆ magnitude()

double magnitude ( ) const
inline
Returns
The magnitude of the vector.

◆ magnitude_2()

double magnitude_2 ( ) const
inline
Returns
The square of the magnitude of the vector. This avoids taking a square root.

◆ operator*=()

Vector3d & operator*= ( double  d)
inline

◆ operator+=()

Vector3d & operator+= ( const Vector3d v)
inline

◆ operator-=()

Vector3d & operator-= ( const Vector3d v)
inline

◆ operator/=()

Vector3d & operator/= ( double  d)
inline

◆ operator=()

Vector3d & operator= ( const Vector3d v)
default

◆ operator[]() [1/2]

double & operator[] ( int  i)
inline

◆ operator[]() [2/2]

double operator[] ( int  i) const
inline

◆ scaleToUnitVector()

void scaleToUnitVector ( )
inline

Scales the vector to unit length. If it is a zero vector, a ScaledZeroVectorError exception is thrown.

◆ ScaleToUnitVector()

void ScaleToUnitVector ( )
inline

◆ setToZero()

void setToZero ( )
inline

◆ SetToZero()

void SetToZero ( )
inline

◆ unitVector()

Vector3d unitVector ( ) const
inline
Returns
A unit length version of the vector.
Warning
If the vector happens to be a zero vector, then a zero vector is returned.

◆ UnitVector()

Vector3d UnitVector ( ) const
inline

◆ vectorProjection()

Vector3d vectorProjection ( const Vector3d v)
inline

Friends And Related Function Documentation

◆ cosAngle()

double cosAngle ( const Vector3d t1,
const Vector3d t2 
)
related
Returns
The cosine of the angle between vectors t1 and t2. This is more efficient than computing (t1.t2) / (|t1||t2|) because it uses only one sqrt() call, not two. Note that checks are performed to ensure that the return value is in the range [-1,1].

◆ crossProduct()

Vector3d crossProduct ( const Vector3d t1,
const Vector3d t2 
)
related

t1 and t2 can be any arbitrary vectors (including being parallel, in which case a zero vector will be returned).

◆ dotProduct()

double dotProduct ( const Vector3d t1,
const Vector3d t2 
)
related
Returns
The dot product of two vectors t1 and t2.

◆ magnitude()

double magnitude ( const Vector3d v)
related

◆ magnitude_2()

double magnitude_2 ( const Vector3d v)
related

◆ operator!=()

bool operator!= ( const Vector3d v0,
const Vector3d v1 
)
related

◆ operator*() [1/2]

Vector3d operator* ( const Vector3d t,
double  d 
)
related

◆ operator*() [2/2]

Vector3d operator* ( double  d,
const Vector3d t 
)
related

◆ operator+()

Vector3d operator+ ( const Vector3d t1,
const Vector3d t2 
)
related

◆ operator-() [1/2]

Vector3d operator- ( const Vector3d t1)
related

◆ operator-() [2/2]

Vector3d operator- ( const Vector3d t1,
const Vector3d t2 
)
related

◆ operator/()

Vector3d operator/ ( const Vector3d t,
double  d 
)
related

◆ operator==()

bool operator== ( const Vector3d v0,
const Vector3d v1 
)
related

◆ scalarTripleProduct()

double scalarTripleProduct ( const Vector3d t1,
const Vector3d t2,
const Vector3d t3 
)
related
Returns
t1.(t2 x t3).

◆ sinAngle()

double sinAngle ( const Vector3d t1,
const Vector3d t2 
)
related
Returns
The sine of the angle between vectors t1 and t2. This is more efficient than computing |t1 x t2| / (|t1||t2|) because it uses only one sqrt() call, not three. Note that checks are performed to ensure that the return value is in the range [-1,1].

◆ unitVector()

Vector3d unitVector ( const Vector3d v)
related

Member Data Documentation

◆ x

double x

◆ y

double y

◆ z

double z