Helios++
Helios software for LiDAR simulations
SurfaceInspector::maths::Vector< T > Class Template Reference

Class providing vector operations. More...

#include <Vector.hpp>

Inheritance diagram for SurfaceInspector::maths::Vector< T >:
Collaboration diagram for SurfaceInspector::maths::Vector< T >:

Static Public Member Functions

static vector< T > add (vector< T > const u, vector< T > const v)
 Add two vectors. More...
 
static vector< T > subtract (vector< T > const u, vector< T > const v)
 Subtract two vectors. More...
 
static vector< T > scalarAdd (vector< T > const u, T const scalar)
 Add the scalar to all elements in vector \(\overline{u}\). More...
 
static vector< T > scalarSubtract (vector< T > const u, T const scalar)
 Subtract the scalar to all elements in vector \(\overline{u}\). More...
 
static vector< T > scalarMultiply (vector< T > const u, T const scalar)
 Multiply all elements in vector \(overline{u}\) by scalar. More...
 
static vector< T > scalarDivide (vector< T > const u, T const scalar)
 Divide all elements in vector \(\overline{u}\) by scalar. More...
 
static void scalarAddInPlace (vector< T > &u, T const scalar)
 Like scalarAdd function but modifying given vector. More...
 
static void scalarSubtractInPlace (vector< T > &u, T const scalar)
 Like scalarSubtract function but modifying given vector. More...
 
static void scalarMultiplyInPlace (vector< T > &u, T const scalar)
 Like scalarMultiply function but modifying given vector. More...
 
static void scalarDivideInPlace (vector< T > &u, T const scalar)
 Like scalarDivide function but modifying given vector. More...
 
static vector< T > negate (vector< T > const u)
 Compute the opposite of given vector \(u\). More...
 
static bool equals (vector< T > const u, vector< T > const v)
 Check if you vectors are equal or not. More...
 
static T min (vector< T > const &u)
 Obtain the minimum value in given vector. More...
 
static T max (vector< T > const &u)
 Obtain the maximum value in given vector. More...
 
static size_t argmin (vector< T > const &u)
 Obtain the index of minimum value in given vector. More...
 
static size_t argmax (vector< T > const &u)
 Obtain the index of maximum value in given vector. More...
 
static T midrange (vector< T > const &u)
 Compute the midrange \(\lambda\) for given vector. More...
 
static T dotProduct (vector< T > const u, vector< T > const v)
 Compute the dot product between vectors \(\overline{u}\) and \(\overline{v}\). More...
 
static vector< T > crossProduct3D (vector< T > const u, vector< T > const v)
 Compute the 3D cross product between vectors \(\overline{u}\) and \(\overline{v}\). More...
 
static vector< T > hadamardProduct (vector< T > const u, vector< T > const v)
 Compute the hadamard product between vectors \(\overline{u}\) and \(\overline{v}\). More...
 
static T squareNorm (vector< T > const u)
 Compute the square norm (magnitude) of vector \(\overline{u}\). More...
 
static T squareMagnitude (vector< T > const u)
 
static T norm (vector< T > const u)
 Compute the norm (magnitude) of vector \(\overline{u}\), which is the square root of its square norm. More...
 
static T magnitude (vector< T > const u)
 
static vector< T > normalize (vector< T > const u)
 Normalize given vector \(\overline{u}\), obtaining \(\hat{u}\). More...
 
static vector< T > normalize (vector< T > const u, T const norm)
 Like Vector::normalize(vector<T> const) but providing a precomputed norm so it is not necessary to compute it. Hence, it is faster as it performs less operations. More...
 
static void normalizeInPlace (vector< T > &u)
 Like Vector::normalize(vector<T> const) but modifying given vector instead of creating new one. More...
 
static void normalizeInPlace (vector< T > &u, T const norm)
 Like Vector::normalize(vector<T> const, T const) but modifying given vector instead of creating new one. More...
 
static T angle (vector< T > const u, vector< T > const v, bool alreadyNormalized=false)
 Compute the angle between two given vectors \(overline{u}\) and \(\overline{v}\). More...
 
static T acuteAngle (vector< T > const u, vector< T > const v, bool alreadyNormalized=false)
 Compute the \(\theta \leq \frac{\pi}{2}\) angle between two given vectors \(\vec{u}\) and \(\vec{v}\). More...
 
static T toAngle2D (vector< T > const u)
 Compute the 2D angle coming from two first components of vector \(\overline{u}\). More...
 
static vector< T > findOrthogonal (vector< T > const v)
 Find a orthogonal vector with respect to \(v\). More...
 
static vector< T > findOrthonormal (vector< T > const v)
 Like findOrthogonal(vector<T> const) but returning a normalized orthogonal vector. More...
 
static vector< vector< T > > findOrthonormals (vector< vector< T >> const V)
 Like findOrthonormal(vector<T> const) but applied to a vector of vectors instead of a single vector. More...
 
static vector< vector< T > > xyRotations (size_t const depth, bool complement)
 Compute normal vectors representing different rotations on 2D. More...
 
static bool isNull (vector< T > const &v)
 Check if \(\vec{v}\) is a null vector (all zero) or not. More...
 
static vector< T > project (vector< T > const v, vector< T > const u)
 Project vector \(v\) over vector \(u\). More...
 
static vector< T > project (vector< T > const v, vector< vector< T >> const u)
 Project vector \(v\) over subspace \(u\). More...
 
static vector< T > diff (vector< T > const u)
 Compute \(v\) as the discrete differences of vector \(u\). More...
 

Detailed Description

template<typename T>
class SurfaceInspector::maths::Vector< T >

Class providing vector operations.

Author
Alberto M. Esmoris Pena
Version
1.0
Template Parameters
TType of element used by the vector

Member Function Documentation

◆ acuteAngle()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::acuteAngle ( vector< T > const  u,
vector< T > const  v,
bool  alreadyNormalized = false 
)
static

Compute the \(\theta \leq \frac{\pi}{2}\) angle between two given vectors \(\vec{u}\) and \(\vec{v}\).

\[ {\theta}' = \arccos{\left( \frac{\langle{\overline{u},\overline{v}}\rangle} {||\overline{u}||\cdot||\overline{v}||} \right)} \]

When \({\theta}' \leq \frac{\pi}{2}\) then \(\theta = {\theta}'\), otherwise \(\theta = \pi - {\theta}'\)

Parameters
uFirst vector
vSecond vector
alreadyNormalizedTrue when vectors are already normalized so normalization is not necessary and computation will be faster, false otherwise
Returns
\(\theta \leq \frac{\pi}{2}\) angle between vectors \(\overline{u}\) and \(\overline{v}\)

◆ add()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::add ( vector< T > const  u,
vector< T > const  v 
)
static

Add two vectors.

Returns
Vector from addition

◆ angle()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::angle ( vector< T > const  u,
vector< T > const  v,
bool  alreadyNormalized = false 
)
static

Compute the angle between two given vectors \(overline{u}\) and \(\overline{v}\).

\[ \theta = \arccos{\left( \frac{\overline{u}\cdot\overline{v}} {||\overline{u}||\cdot||\overline{v}||} \right)} \]

Parameters
uFirst vector
vSecond vector
alreadyNormalizedTrue when vectors are already normalized so normalization is not necessary and computation will be faster, false otherwise
Returns
Angle between vectors \(\overline{u}\) and \(\overline{v}\)

◆ argmax()

template<typename T >
static size_t SurfaceInspector::maths::Vector< T >::argmax ( vector< T > const &  u)
static

Obtain the index of maximum value in given vector.

Parameters
uVector which maximum value index must be obtained
Returns
Maximum value index from given vector

◆ argmin()

template<typename T >
static size_t SurfaceInspector::maths::Vector< T >::argmin ( vector< T > const &  u)
static

Obtain the index of minimum value in given vector.

Parameters
uVector which minimum value index must be obtained
Returns
Minimum value index from given vector

◆ crossProduct3D()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::crossProduct3D ( vector< T > const  u,
vector< T > const  v 
)
static

Compute the 3D cross product between vectors \(\overline{u}\) and \(\overline{v}\).

\[ \overline{w} = \overline{u} \times \overline{v} = ( u_{y}v_{z} - u_{z}v_{y}, u_{z}v_{x} - u_{x}v_{z}, u_{x}v_{y} - u_{y}v_{x} ) \]

Parameters
uFirst vector
vSecond vector
Returns
Cross product between \(\overline{u}\) and \(\overline{v}\)

◆ diff()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::diff ( vector< T > const  u)
static

Compute \(v\) as the discrete differences of vector \(u\).

The cardinality of \(v\) will be \(|v| = |u| - 1\).

Also, \(v_i = u_{i+1} - u_{i}\), so:

\[ v = \left(u_{2}-u_{1}, \ldots, u_{n}-u_{n-1}\right) \]

Parameters
uVector to differentiate
Returns
\(v\) vector as the discrete differences of vector \(u\)

◆ dotProduct()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::dotProduct ( vector< T > const  u,
vector< T > const  v 
)
static

Compute the dot product between vectors \(\overline{u}\) and \(\overline{v}\).

\[ \overline{u} \cdot \overline{v} = \sum_{i=1}^{n}{u_{i} v_{i}} \]

Parameters
uFirst vector
vSecond vector
Returns
Dot product between \(\overline{u}\) and \(\overline{v}\)

◆ equals()

template<typename T >
static bool SurfaceInspector::maths::Vector< T >::equals ( vector< T > const  u,
vector< T > const  v 
)
static

Check if you vectors are equal or not.

Two vectors \(u\) and \(v\) are considered to be equal when \(\forall i,\, u_{i}=v_{i}\)

Parameters
uFirst vector to compare with
vSecond vector to compare with
Returns
True if vectors are exactly equal, false otherwise

◆ findOrthogonal()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::findOrthogonal ( vector< T > const  v)
static

Find a orthogonal vector with respect to \(v\).

Let u be the orthogonal vector which can be defined as follows:

\[ u_{i} = \frac{1}{n_{i}}\sum_{i{\neq}j}{u_{j}v_{j}} \]

Parameters
vVector which orthogonal must be found
Returns
Vector orthogonal to \(v\)
See also
Vector::findOrthonormal(vector<T> const)

◆ findOrthonormal()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::findOrthonormal ( vector< T > const  v)
inlinestatic

Like findOrthogonal(vector<T> const) but returning a normalized orthogonal vector.

Returns
Orthonormal vector with respect to v
See also
Vector::findOrthogonal(vector<T> const)
Vector::normalize

◆ findOrthonormals()

template<typename T >
static vector<vector<T> > SurfaceInspector::maths::Vector< T >::findOrthonormals ( vector< vector< T >> const  V)
static

Like findOrthonormal(vector<T> const) but applied to a vector of vectors instead of a single vector.

See also
Vector::findOrthonormal(vector<T> const)

◆ hadamardProduct()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::hadamardProduct ( vector< T > const  u,
vector< T > const  v 
)
static

Compute the hadamard product between vectors \(\overline{u}\) and \(\overline{v}\).

\[ \overline{w} = \overline{u} \odot \overline{v} = (u_{1}v_{1}, \ldots , u_{n}v_{n}) \]

Parameters
uFirst vector
vSecond vector
Returns
Hadamard product between \(\overline{u}\) and \(\overline{v}\)

◆ isNull()

template<typename T >
static bool SurfaceInspector::maths::Vector< T >::isNull ( vector< T > const &  v)
static

Check if \(\vec{v}\) is a null vector (all zero) or not.

Parameters
vCheck to be checked for nullity
Returns
True if \(\vec{v}\) is a null vector, false otherwise.

◆ magnitude()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::magnitude ( vector< T > const  u)
inlinestatic
See also
Vector::norm

◆ max()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::max ( vector< T > const &  u)
static

Obtain the maximum value in given vector.

Parameters
uVector which maximum value must be obtained
Returns
Maximum value from given vector

◆ midrange()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::midrange ( vector< T > const &  u)
static

Compute the midrange \(\lambda\) for given vector.

\[ \lambda = \frac{u_{max}+u_{min}}{2} \]

Parameters
uVector which midrange must be obtained
Returns
Midrange for given vector

◆ min()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::min ( vector< T > const &  u)
static

Obtain the minimum value in given vector.

Parameters
uVector which minimum value must be obtained
Returns
Minimum value from given vector

◆ negate()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::negate ( vector< T > const  u)
static

Compute the opposite of given vector \(u\).

\[ u = (u_{1}, ..., u_{n}) \implies -u = (-u_{1}, ..., -u_{n}) \]

Parameters
uVector to be negated
Returns
Negated \(u\)

◆ norm()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::norm ( vector< T > const  u)
static

Compute the norm (magnitude) of vector \(\overline{u}\), which is the square root of its square norm.

\[ ||\overline{u}|| = \sqrt{\sum_{i=1}^{n}{u_{i}^{2}}} \]

Parameters
uVector which norm (magnitude) must be computed
Returns
Norm (magnitude) of vector \(\overline{u}\)
See also
Vector::squareNorm

◆ normalize() [1/2]

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::normalize ( vector< T > const  u)
static

Normalize given vector \(\overline{u}\), obtaining \(\hat{u}\).

\[ \hat{u} = \left(\frac{u_{i}}{||\overline{u}||} ,\ldots, \frac{u_{i}}{||\overline{u}||}\right) \]

Parameters
uVector to be normalized
Returns
Normalized vector \(\hat{u}\)

◆ normalize() [2/2]

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::normalize ( vector< T > const  u,
T const  norm 
)
static

Like Vector::normalize(vector<T> const) but providing a precomputed norm so it is not necessary to compute it. Hence, it is faster as it performs less operations.

See also
Vector::normalize(vector<T> const)

◆ normalizeInPlace() [1/2]

template<typename T >
static void SurfaceInspector::maths::Vector< T >::normalizeInPlace ( vector< T > &  u)
static

Like Vector::normalize(vector<T> const) but modifying given vector instead of creating new one.

See also
Vector::normalize(vector<T> const)

◆ normalizeInPlace() [2/2]

template<typename T >
static void SurfaceInspector::maths::Vector< T >::normalizeInPlace ( vector< T > &  u,
T const  norm 
)
static

Like Vector::normalize(vector<T> const, T const) but modifying given vector instead of creating new one.

See also
Vector::normalize(vector<T> const, T const)

◆ project() [1/2]

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::project ( vector< T > const  v,
vector< T > const  u 
)
static

Project vector \(v\) over vector \(u\).

\[ \mathrm{proj}_{u}{v} = \frac{\langle{u,v}\rangle}{\langle{u,u}\rangle} u \]

Parameters
vVector to be projected
uVector to project over it
Returns
Projection of v over u

◆ project() [2/2]

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::project ( vector< T > const  v,
vector< vector< T >> const  u 
)
static

Project vector \(v\) over subspace \(u\).

Considering \(u = \langle{b_{1}, \ldots, b_{n}}\rangle\)

\[ \mathrm{proj}_{u}{v} = \frac{\langle{v,b_{1}}\rangle}{\langle{b_{1},b_{1}}\rangle} b_{1} + \ldots + \frac{\langle{v,b_{n}}\rangle}{\langle{b_{n},b_{n}}\rangle} b_{n} = \sum_{i=1}^{n}{\frac{\langle{v,b_{i}}\rangle}{||b_{i}||^{2}}b_{i}} \]

Parameters
vVector to be projected
uBasis of the vector subspace to project over it
Returns
Projection of v over u

◆ scalarAdd()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::scalarAdd ( vector< T > const  u,
T const  scalar 
)
static

Add the scalar to all elements in vector \(\overline{u}\).

Returns
Vector resulting from addition

◆ scalarAddInPlace()

template<typename T >
static void SurfaceInspector::maths::Vector< T >::scalarAddInPlace ( vector< T > &  u,
T const  scalar 
)
static

Like scalarAdd function but modifying given vector.

See also
Vector::scalarAdd

◆ scalarDivide()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::scalarDivide ( vector< T > const  u,
T const  scalar 
)
static

Divide all elements in vector \(\overline{u}\) by scalar.

Returns
Vector resulting from division

◆ scalarDivideInPlace()

template<typename T >
static void SurfaceInspector::maths::Vector< T >::scalarDivideInPlace ( vector< T > &  u,
T const  scalar 
)
static

Like scalarDivide function but modifying given vector.

See also
Vector::scalarDivide

◆ scalarMultiply()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::scalarMultiply ( vector< T > const  u,
T const  scalar 
)
static

Multiply all elements in vector \(overline{u}\) by scalar.

Returns
Vector resulting from multiplication

◆ scalarMultiplyInPlace()

template<typename T >
static void SurfaceInspector::maths::Vector< T >::scalarMultiplyInPlace ( vector< T > &  u,
T const  scalar 
)
static

Like scalarMultiply function but modifying given vector.

See also
Vector::scalarMultiply

◆ scalarSubtract()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::scalarSubtract ( vector< T > const  u,
T const  scalar 
)
static

Subtract the scalar to all elements in vector \(\overline{u}\).

Returns
Vector resulting from subtraction

◆ scalarSubtractInPlace()

template<typename T >
static void SurfaceInspector::maths::Vector< T >::scalarSubtractInPlace ( vector< T > &  u,
T const  scalar 
)
static

Like scalarSubtract function but modifying given vector.

See also
Vector::scalarSubtract

◆ squareMagnitude()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::squareMagnitude ( vector< T > const  u)
inlinestatic

◆ squareNorm()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::squareNorm ( vector< T > const  u)
static

Compute the square norm (magnitude) of vector \(\overline{u}\).

\[ ||\overline{u}||^{2} = \sum_{i=1}^{n}{u_{i}^{2}} \]

Parameters
uVector which square norm (magnitude) must be computed
Returns
Square norm (magnitude) of vector \(\overline{u}\)

◆ subtract()

template<typename T >
static vector<T> SurfaceInspector::maths::Vector< T >::subtract ( vector< T > const  u,
vector< T > const  v 
)
inlinestatic

Subtract two vectors.

Returns
Vector from subtraction

◆ toAngle2D()

template<typename T >
static T SurfaceInspector::maths::Vector< T >::toAngle2D ( vector< T > const  u)
static

Compute the 2D angle coming from two first components of vector \(\overline{u}\).

Parameters
uVector which 2D angle must be obtained
Returns
Angle of first two components of \(\overline{u}\) in interval \([-\pi, +\pi]\)

◆ xyRotations()

template<typename T >
static vector<vector<T> > SurfaceInspector::maths::Vector< T >::xyRotations ( size_t const  depth,
bool  complement 
)
static

Compute normal vectors representing different rotations on 2D.

Rotations are computed according to following formula

\[ x' = cos(\theta)x - sin(\theta)y \\ y' = sin(\theta)x + cos(\theta)y \]

Parameters
depthThe number of rotations computed in the semi-circumference space.
complementWhen it is false, as many vectors as depth will be returned. However, when it is true, as many vectors as depth x 2 will be returned, since the entire circumference will be considered through negation of vectors in the semi-circumference space
Returns
Either depth rotations on the semi-circumference space (when complement is false) or (2 x depth) rotations on the circumference space (when complement is true)

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