CellModules
MecaCell::Vector3D Class Reference

general purpose 3D vector/point class. More...

#include <vector3D.h>

Public Member Functions

 Vector3D (double a, double b, double c)
 
 Vector3D ()
 
 Vector3D (double a)
 
 Vector3D (std::array< double, 3 > c)
 
 Vector3D (const Vector3D &v)
 
 Vector3D (Vector3D &&v)
 
Vector3Doperator= (const Vector3D &other)
 assignment operator for copy constructing a vector More...
 
double dot (const Vector3D &v) const
 dot product calculation More...
 
const Vector3D cross (const Vector3D &v) const
 cross product calculation More...
 
double & xRef ()
 
double & yRef ()
 
double & zRef ()
 
double x () const
 
double y () const
 
double z () const
 
void setX (const double f)
 setter for x coordinate More...
 
void setY (const double f)
 setter for y coordinate More...
 
void setZ (const double f)
 setter for z coordinate More...
 
void random ()
 sets the current vector as a random normalized one. Uniform direction distribution on all directions of a sphere. More...
 
Vector3D deltaDirection (double amount)
 returns a vector randomly tilted relatively to the original one More...
 
bool isZero () const
 returns true if all vector coordinates are equal to zero More...
 
Vector3Doperator*= (double d)
 scalar multiplication operator More...
 
Vector3Doperator/= (double d)
 scalar division operator More...
 
Vector3Doperator+= (const Vector3D &v)
 addition operator More...
 
Vector3Doperator-= (const Vector3D &v)
 substract operator More...
 
double length () const
 compute the length of the vector More...
 
double sqlength () const
 compute the square length of the current vector (faster than length) More...
 
Vector3D rotated (double angle, const Vector3D &vec) const
 gives a rotated copy of the current vector More...
 
Vector3D rotated (const Rotation< Vector3D > &r) const
 gives a rotated copy of the current vector More...
 
void normalize ()
 normalizes the vector More...
 
Vector3D normalized () const
 returns a normalized copy of the current vector More...
 
std::string toString () const
 
int getHash (const int a, const int b) const
 fast hash for two ints More...
 
int getHash () const
 fast hash method More...
 
void iterateTo (const Vector3D &v, const std::function< void(const Vector3D &)> &fun, const double inc=1) const
 helper method to iterates over a 3D rectangular cuboid bounded by two corner vectors More...
 
Vector3D ortho () const
 deterministic generation of an orthogonal vector More...
 
Vector3D ortho (const Vector3D &v) const
 
 EXPORTABLE (Vector3D, KV(coords))
 

Static Public Member Functions

static Vector3D randomUnit ()
 creates a random normalized vector. Uniform direction distribution on all directions of a sphere. More...
 
static Vector3D zero ()
 constructs a zero vector More...
 
static void addAsAngularVelocity (const Vector3D &v, Rotation< Vector3D > &r)
 adds a vector representing an angular Velocity (or any rotation coded on only one vector) to an existing rotation More...
 
static Rotation< Vector3DgetRotation (const Vector3D &v0, const Vector3D &v1)
 computes the rotation from one vector to another More...
 
static double rayCast (const Vector3D &o, const Vector3D &n, const Vector3D &p, const Vector3D &r)
 simple raycasting on a plane More...
 
static Vector3D getProjectionOnPlane (const Vector3D &o, const Vector3D &n, const Vector3D &p)
 project a point on a plane More...
 
static Rotation< Vector3DrotateRotation (const Rotation< Vector3D > &start, const Rotation< Vector3D > &offset)
 rotates the axis of rotation of a rotation More...
 
static Rotation< Vector3DaddRotations (const Rotation< Vector3D > &R0, const Rotation< Vector3D > &R1)
 adds two rotations More...
 
static Rotation< Vector3DgetRotation (const Vector3D &X0, const Vector3D &Y0, const Vector3D &X1, const Vector3D &Y1)
 computes the rotation transform from basis X0,Y0 to X1,Y1 More...
 
static Rotation< Vector3DgetRotation (const Basis< Vector3D > &b0, const Basis< Vector3D > &b1)
 computes the rotation transform from basis b0 to b1 More...
 
static Vector3D getProjection (const Vector3D &A, const Vector3D &B, const Vector3D &P)
 computes the orthogonal projection of a point onto a segment AB More...
 

Public Attributes

std::array< double, 3 > coords
 

Static Public Attributes

static const int dimension = 3
 

Friends

bool operator== (const Vector3D &v1, const Vector3D &v2)
 
bool operator!= (const Vector3D &v1, const Vector3D &v2)
 
Vector3D operator+ (const Vector3D &v1, const Vector3D &v2)
 
Vector3D operator+ (const Vector3D &v1, double f)
 
Vector3D operator+ (double f, const Vector3D &v1)
 
Vector3D operator- (const Vector3D &v1, const Vector3D &v2)
 
Vector3D operator- (const Vector3D &v1, double f)
 
Vector3D operator- (double f, const Vector3D &v1)
 
Vector3D operator* (double factor, const Vector3D &vector)
 
Vector3D operator* (const Vector3D &vector, double factor)
 
Vector3D operator* (const Vector3D &v1, const Vector3D &v2)
 
Vector3D operator- (const Vector3D &vector)
 
Vector3D operator/ (const Vector3D &vector, double divisor)
 
ostream & operator<< (ostream &out, const Vector3D &v)
 

Detailed Description

general purpose 3D vector/point class.

Definition at line 20 of file vector3D.h.

Constructor & Destructor Documentation

◆ Vector3D() [1/6]

MecaCell::Vector3D::Vector3D ( double  a,
double  b,
double  c 
)
inline

Definition at line 25 of file vector3D.h.

◆ Vector3D() [2/6]

MecaCell::Vector3D::Vector3D ( )
inline

Definition at line 28 of file vector3D.h.

◆ Vector3D() [3/6]

MecaCell::Vector3D::Vector3D ( double  a)
inlineexplicit

Definition at line 29 of file vector3D.h.

◆ Vector3D() [4/6]

MecaCell::Vector3D::Vector3D ( std::array< double, 3 >  c)
inlineexplicit

Definition at line 30 of file vector3D.h.

◆ Vector3D() [5/6]

MecaCell::Vector3D::Vector3D ( const Vector3D v)
inline

Definition at line 31 of file vector3D.h.

◆ Vector3D() [6/6]

MecaCell::Vector3D::Vector3D ( Vector3D &&  v)
inline

Definition at line 32 of file vector3D.h.

Member Function Documentation

◆ addAsAngularVelocity()

static void MecaCell::Vector3D::addAsAngularVelocity ( const Vector3D v,
Rotation< Vector3D > &  r 
)
inlinestatic

adds a vector representing an angular Velocity (or any rotation coded on only one vector) to an existing rotation

Parameters
vthe single vector coded rotation (its length codes for the angle)
rthe rotation which is going to be modified

Definition at line 305 of file vector3D.h.

◆ addRotations()

static Rotation< Vector3D > MecaCell::Vector3D::addRotations ( const Rotation< Vector3D > &  R0,
const Rotation< Vector3D > &  R1 
)
inlinestatic

adds two rotations

Parameters
R0
R1
Returns

Definition at line 387 of file vector3D.h.

◆ cross()

const Vector3D MecaCell::Vector3D::cross ( const Vector3D v) const
inline

cross product calculation

Parameters
va Vector3D
Returns
the cross product of this vector against v

Definition at line 65 of file vector3D.h.

◆ deltaDirection()

Vector3D MecaCell::Vector3D::deltaDirection ( double  amount)
inline

returns a vector randomly tilted relatively to the original one

Parameters
amountthe width of the normal distribution
Returns
a 3D vector

Definition at line 157 of file vector3D.h.

◆ dot()

double MecaCell::Vector3D::dot ( const Vector3D v) const
inline

dot product calculation

Parameters
va Vector3D
Returns
the dot product of this vector against v

Definition at line 54 of file vector3D.h.

◆ EXPORTABLE()

MecaCell::Vector3D::EXPORTABLE ( Vector3D  ,
KV(coords  
)

◆ getHash() [1/2]

int MecaCell::Vector3D::getHash ( ) const
inline

fast hash method

Returns

Definition at line 483 of file vector3D.h.

◆ getHash() [2/2]

int MecaCell::Vector3D::getHash ( const int  a,
const int  b 
) const
inline

fast hash for two ints

Parameters
a
b
Returns

Definition at line 471 of file vector3D.h.

◆ getProjection()

static Vector3D MecaCell::Vector3D::getProjection ( const Vector3D A,
const Vector3D B,
const Vector3D P 
)
inlinestatic

computes the orthogonal projection of a point onto a segment AB

Parameters
Athe origin of the segment
Bthe endpoint of the segment
Pthe point to be projected
Returns

Definition at line 437 of file vector3D.h.

◆ getProjectionOnPlane()

static Vector3D MecaCell::Vector3D::getProjectionOnPlane ( const Vector3D o,
const Vector3D n,
const Vector3D p 
)
inlinestatic

project a point on a plane

Parameters
oa point in the plane
nthe plane's normal
pthe point to be projected onto the surface of the plane
Returns
the projection of p onto a plane defined by its normal n and an offset o

Definition at line 362 of file vector3D.h.

◆ getRotation() [1/3]

static Rotation< Vector3D > MecaCell::Vector3D::getRotation ( const Basis< Vector3D > &  b0,
const Basis< Vector3D > &  b1 
)
inlinestatic

computes the rotation transform from basis b0 to b1

Parameters
X0
Y0
X1
Y1
Returns

Definition at line 423 of file vector3D.h.

◆ getRotation() [2/3]

static Rotation< Vector3D > MecaCell::Vector3D::getRotation ( const Vector3D v0,
const Vector3D v1 
)
inlinestatic

computes the rotation from one vector to another

Parameters
v0first vector
v1second vector
Returns
a rotation that can transform v0 into v1

Definition at line 322 of file vector3D.h.

◆ getRotation() [3/3]

static Rotation< Vector3D > MecaCell::Vector3D::getRotation ( const Vector3D X0,
const Vector3D Y0,
const Vector3D X1,
const Vector3D Y1 
)
inlinestatic

computes the rotation transform from basis X0,Y0 to X1,Y1

Parameters
X0
Y0
X1
Y1
Returns

Definition at line 404 of file vector3D.h.

◆ isZero()

bool MecaCell::Vector3D::isZero ( ) const
inline

returns true if all vector coordinates are equal to zero

Returns

Definition at line 177 of file vector3D.h.

◆ iterateTo()

void MecaCell::Vector3D::iterateTo ( const Vector3D v,
const std::function< void(const Vector3D &)> &  fun,
const double  inc = 1 
) const
inline

helper method to iterates over a 3D rectangular cuboid bounded by two corner vectors

Parameters
vthe upper bound corner (lower bound is the current vector)
funa function taking the upper bound vector as well as an increent (default = 1.0)
incthe increment step

Definition at line 498 of file vector3D.h.

◆ length()

double MecaCell::Vector3D::length ( ) const
inline

compute the length of the vector

Returns

Definition at line 257 of file vector3D.h.

◆ normalize()

void MecaCell::Vector3D::normalize ( )
inline

normalizes the vector

Definition at line 445 of file vector3D.h.

◆ normalized()

Vector3D MecaCell::Vector3D::normalized ( ) const
inline

returns a normalized copy of the current vector

Returns

Definition at line 452 of file vector3D.h.

◆ operator*=()

Vector3D & MecaCell::Vector3D::operator*= ( double  d)
inline

scalar multiplication operator

Parameters
d
Returns

Definition at line 188 of file vector3D.h.

◆ operator+=()

Vector3D & MecaCell::Vector3D::operator+= ( const Vector3D v)
inline

addition operator

Parameters
v
Returns

Definition at line 216 of file vector3D.h.

◆ operator-=()

Vector3D & MecaCell::Vector3D::operator-= ( const Vector3D v)
inline

substract operator

Parameters
v
Returns

Definition at line 230 of file vector3D.h.

◆ operator/=()

Vector3D & MecaCell::Vector3D::operator/= ( double  d)
inline

scalar division operator

Parameters
d
Returns

Definition at line 202 of file vector3D.h.

◆ operator=()

Vector3D & MecaCell::Vector3D::operator= ( const Vector3D other)
inline

assignment operator for copy constructing a vector

Parameters
other
Returns

Definition at line 41 of file vector3D.h.

◆ ortho() [1/2]

Vector3D MecaCell::Vector3D::ortho ( ) const
inline

deterministic generation of an orthogonal vector

Returns

Definition at line 519 of file vector3D.h.

◆ ortho() [2/2]

Vector3D MecaCell::Vector3D::ortho ( const Vector3D v) const
inline

Definition at line 526 of file vector3D.h.

◆ random()

void MecaCell::Vector3D::random ( )
inline

sets the current vector as a random normalized one. Uniform direction distribution on all directions of a sphere.

Definition at line 131 of file vector3D.h.

◆ randomUnit()

static Vector3D MecaCell::Vector3D::randomUnit ( )
inlinestatic

creates a random normalized vector. Uniform direction distribution on all directions of a sphere.

Returns
a 3D vector

Definition at line 144 of file vector3D.h.

◆ rayCast()

static double MecaCell::Vector3D::rayCast ( const Vector3D o,
const Vector3D n,
const Vector3D p,
const Vector3D r 
)
inlinestatic

simple raycasting on a plane

Parameters
oa point in the plane
nnormal of the plane
porigin of the ray
rdirection of the ray
Returns
l such that p + l.r lies on the plane defined by its normal n and an offset o l > 0 means that the ray hits the plane, l < 0 means that the racoords[1] does not face the plane l = 0 means that the ray is parallel to the plane or that p is on the plane

Definition at line 346 of file vector3D.h.

◆ rotated() [1/2]

Vector3D MecaCell::Vector3D::rotated ( const Rotation< Vector3D > &  r) const
inline

gives a rotated copy of the current vector

Parameters
rthe rotation
Returns
a rotated copy of the current vector

Definition at line 291 of file vector3D.h.

◆ rotated() [2/2]

Vector3D MecaCell::Vector3D::rotated ( double  angle,
const Vector3D vec 
) const
inline

gives a rotated copy of the current vector

Parameters
anglethe rotation angle in radians
vecthe axis of rotation
Returns
a rotated copy of the current vector

Definition at line 277 of file vector3D.h.

◆ rotateRotation()

static Rotation< Vector3D > MecaCell::Vector3D::rotateRotation ( const Rotation< Vector3D > &  start,
const Rotation< Vector3D > &  offset 
)
inlinestatic

rotates the axis of rotation of a rotation

Parameters
start
offset
Returns

Definition at line 375 of file vector3D.h.

◆ setX()

void MecaCell::Vector3D::setX ( const double  f)
inline

setter for x coordinate

Parameters
fthe new value

Definition at line 113 of file vector3D.h.

◆ setY()

void MecaCell::Vector3D::setY ( const double  f)
inline

setter for y coordinate

Parameters
fthe new value

Definition at line 119 of file vector3D.h.

◆ setZ()

void MecaCell::Vector3D::setZ ( const double  f)
inline

setter for z coordinate

Parameters
fthe new value

Definition at line 125 of file vector3D.h.

◆ sqlength()

double MecaCell::Vector3D::sqlength ( ) const
inline

compute the square length of the current vector (faster than length)

Returns

Definition at line 265 of file vector3D.h.

◆ toString()

std::string MecaCell::Vector3D::toString ( ) const
inline

Definition at line 457 of file vector3D.h.

◆ x()

double MecaCell::Vector3D::x ( ) const
inline
Returns
the const value of the x coordinate

Definition at line 94 of file vector3D.h.

◆ xRef()

double & MecaCell::Vector3D::xRef ( )
inline
Returns
a reference to the x coordinate

Definition at line 76 of file vector3D.h.

◆ y()

double MecaCell::Vector3D::y ( ) const
inline
Returns
the const value of the y coordinate

Definition at line 100 of file vector3D.h.

◆ yRef()

double & MecaCell::Vector3D::yRef ( )
inline
Returns
a reference to the y coordinate

Definition at line 82 of file vector3D.h.

◆ z()

double MecaCell::Vector3D::z ( ) const
inline
Returns
the const value of the z coordinate

Definition at line 106 of file vector3D.h.

◆ zero()

static Vector3D MecaCell::Vector3D::zero ( )
inlinestatic

constructs a zero vector

Returns

Definition at line 170 of file vector3D.h.

◆ zRef()

double & MecaCell::Vector3D::zRef ( )
inline
Returns
a reference to the z coordinate

Definition at line 88 of file vector3D.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Vector3D v1,
const Vector3D v2 
)
friend

Definition at line 541 of file vector3D.h.

◆ operator* [1/3]

Vector3D operator* ( const Vector3D v1,
const Vector3D v2 
)
friend

Definition at line 561 of file vector3D.h.

◆ operator* [2/3]

Vector3D operator* ( const Vector3D vector,
double  factor 
)
friend

Definition at line 569 of file vector3D.h.

◆ operator* [3/3]

Vector3D operator* ( double  factor,
const Vector3D vector 
)
friend

Definition at line 566 of file vector3D.h.

◆ operator+ [1/3]

Vector3D operator+ ( const Vector3D v1,
const Vector3D v2 
)
friend

Definition at line 546 of file vector3D.h.

◆ operator+ [2/3]

Vector3D operator+ ( const Vector3D v1,
double  f 
)
friend

Definition at line 553 of file vector3D.h.

◆ operator+ [3/3]

Vector3D operator+ ( double  f,
const Vector3D v1 
)
friend

Definition at line 550 of file vector3D.h.

◆ operator- [1/4]

Vector3D operator- ( const Vector3D v1,
const Vector3D v2 
)
friend

Definition at line 557 of file vector3D.h.

◆ operator- [2/4]

Vector3D operator- ( const Vector3D v1,
double  f 
)
friend

Definition at line 576 of file vector3D.h.

◆ operator- [3/4]

Vector3D operator- ( const Vector3D vector)
friend

Definition at line 580 of file vector3D.h.

◆ operator- [4/4]

Vector3D operator- ( double  f,
const Vector3D v1 
)
friend

Definition at line 573 of file vector3D.h.

◆ operator/

Vector3D operator/ ( const Vector3D vector,
double  divisor 
)
friend

Definition at line 584 of file vector3D.h.

◆ operator<<

ostream & operator<< ( ostream &  out,
const Vector3D v 
)
friend

Definition at line 587 of file vector3D.h.

◆ operator==

bool operator== ( const Vector3D v1,
const Vector3D v2 
)
friend

Definition at line 537 of file vector3D.h.

Member Data Documentation

◆ coords

std::array<double, 3> MecaCell::Vector3D::coords

Definition at line 22 of file vector3D.h.

◆ dimension

const int MecaCell::Vector3D::dimension = 3
static

Definition at line 24 of file vector3D.h.


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