Helios++
Helios software for LiDAR simulations
Vector.hpp
1 #ifndef _SURFACEINSPECTOR_MATHS_VECTOR_HPP_
2 #define _SURFACEINSPECTOR_MATHS_VECTOR_HPP_
3 
4 #include <vector>
5 
6 #include <surfaceinspector/util/Object.hpp>
7 #include <surfaceinspector/util/SurfaceInspectorException.hpp>
8 
9 using std::vector;
10 
12 
13 namespace SurfaceInspector{ namespace maths {
14 
22 template <typename T>
23 class Vector : public Object{
24 public:
25  // *** BASIC VECTOR OPERATIONS *** //
26  // ********************************* //
31  static vector<T> add(vector<T> const u, vector<T> const v);
32 
37  static inline vector<T> subtract(vector<T> const u, vector<T> const v)
38  {return add(u, negate(v));}
39 
44  static vector<T> scalarAdd(vector<T> const u, T const scalar);
49  static vector<T> scalarSubtract(vector<T> const u, T const scalar);
54  static vector<T> scalarMultiply(vector<T> const u, T const scalar);
59  static vector<T> scalarDivide(vector<T> const u, T const scalar);
64  static void scalarAddInPlace(vector<T> &u, T const scalar);
69  static void scalarSubtractInPlace(vector<T> &u, T const scalar);
74  static void scalarMultiplyInPlace(vector<T> &u, T const scalar);
79  static void scalarDivideInPlace(vector<T> &u, T const scalar);
89  static vector<T> negate(vector<T> const u);
100  static bool equals(vector<T> const u, vector<T> const v);
106  static T min(vector<T> const &u);
112  static T max(vector<T> const &u);
118  static size_t argmin(vector<T> const &u);
124  static size_t argmax(vector<T> const &u);
135  static T midrange(vector<T> const &u);
149  static T dotProduct(vector<T> const u, vector <T> const v);
167  static vector<T> crossProduct3D(vector<T> const u, vector<T> const v);
182  static vector<T> hadamardProduct(vector<T> const u, vector<T> const v);
193  static T squareNorm(vector<T> const u);
197  static inline T squareMagnitude(vector<T> const u)
198  {return normSquare(u);}
211  static T norm(vector<T> const u);
215  static inline T magnitude(vector<T> const u)
216  {return norm(u);}
229  static vector<T> normalize(vector<T> const u);
236  static vector<T> normalize(vector<T> const u, T const norm);
242  static void normalizeInPlace(vector<T> &u);
248  static void normalizeInPlace(vector<T> &u, T const norm);
267  static T angle(
268  vector<T> const u,
269  vector<T> const v,
270  bool alreadyNormalized=false
271  );
294  static T acuteAngle(
295  vector<T> const u,
296  vector<T> const v,
297  bool alreadyNormalized=false
298  );
306  static T toAngle2D(vector<T> const u);
307 
320  static vector<T> findOrthogonal(vector<T> const v);
321 
329  static vector<T> findOrthonormal(vector<T> const v)
330  {return normalize(findOrthogonal(v));}
331 
337  static vector<vector<T>> findOrthonormals(vector<vector<T>> const V);
338 
359  static vector<vector<T>> xyRotations(
360  size_t const depth,
361  bool complement
362  );
363 
369  static bool isNull(vector<T> const &v);
370 
383  static vector<T> project(vector<T> const v, vector<T> const u);
384 
403  static vector<T> project(vector<T> const v, vector<vector<T>> const u);
418  static vector<T> diff(vector<T> const u);
419 };
420 
421 }}
422 
423 #include <surfaceinspector/maths/Vector.tpp>
424 
425 #endif
Class providing vector operations.
Definition: Vector.hpp:23
static void scalarSubtractInPlace(vector< T > &u, T const scalar)
Like scalarSubtract function but modifying given vector.
static void scalarAddInPlace(vector< T > &u, T const scalar)
Like scalarAdd function but modifying given vector.
static vector< T > project(vector< T > const v, vector< vector< T >> const u)
Project vector over subspace .
static T squareMagnitude(vector< T > const u)
Definition: Vector.hpp:197
static vector< T > negate(vector< T > const u)
Compute the opposite of given vector .
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 co...
static size_t argmin(vector< T > const &u)
Obtain the index of minimum value in given vector.
static vector< T > subtract(vector< T > const u, vector< T > const v)
Subtract two vectors.
Definition: Vector.hpp:37
static vector< T > normalize(vector< T > const u)
Normalize given vector , obtaining .
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 o...
static T magnitude(vector< T > const u)
Definition: Vector.hpp:215
static vector< vector< T > > xyRotations(size_t const depth, bool complement)
Compute normal vectors representing different rotations on 2D.
static vector< T > diff(vector< T > const u)
Compute as the discrete differences of vector .
static bool equals(vector< T > const u, vector< T > const v)
Check if you vectors are equal or not.
static T squareNorm(vector< T > const u)
Compute the square norm (magnitude) of vector .
static T dotProduct(vector< T > const u, vector< T > const v)
Compute the dot product between vectors and .
static T norm(vector< T > const u)
Compute the norm (magnitude) of vector , which is the square root of its square norm.
static vector< T > scalarAdd(vector< T > const u, T const scalar)
Add the scalar to all elements in vector .
static vector< T > scalarMultiply(vector< T > const u, T const scalar)
Multiply all elements in vector by scalar.
static vector< T > scalarDivide(vector< T > const u, T const scalar)
Divide all elements in vector by scalar.
static T midrange(vector< T > const &u)
Compute the midrange for given vector.
static T acuteAngle(vector< T > const u, vector< T > const v, bool alreadyNormalized=false)
Compute the angle between two given vectors and .
static vector< T > add(vector< T > const u, vector< T > const v)
Add two vectors.
static void scalarMultiplyInPlace(vector< T > &u, T const scalar)
Like scalarMultiply function but modifying given vector.
static size_t argmax(vector< T > const &u)
Obtain the index of maximum value in given vector.
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.
static vector< T > scalarSubtract(vector< T > const u, T const scalar)
Subtract the scalar to all elements in vector .
static vector< T > crossProduct3D(vector< T > const u, vector< T > const v)
Compute the 3D cross product between vectors and .
static vector< T > findOrthogonal(vector< T > const v)
Find a orthogonal vector with respect to .
static vector< T > hadamardProduct(vector< T > const u, vector< T > const v)
Compute the hadamard product between vectors and .
static bool isNull(vector< T > const &v)
Check if is a null vector (all zero) or not.
static void scalarDivideInPlace(vector< T > &u, T const scalar)
Like scalarDivide function but modifying given vector.
static T toAngle2D(vector< T > const u)
Compute the 2D angle coming from two first components of vector .
static T angle(vector< T > const u, vector< T > const v, bool alreadyNormalized=false)
Compute the angle between two given vectors and .
static T min(vector< T > const &u)
Obtain the minimum value in given vector.
static vector< T > project(vector< T > const v, vector< T > const u)
Project vector over vector .
static void normalizeInPlace(vector< T > &u)
Like Vector::normalize(vector<T> const) but modifying given vector instead of creating new one.
static vector< T > findOrthonormal(vector< T > const v)
Like findOrthogonal(vector<T> const) but returning a normalized orthogonal vector.
Definition: Vector.hpp:329
static T max(vector< T > const &u)
Obtain the maximum value in given vector.
Class representing an object. All surface inspector classes must extend Object.
Definition: Object.hpp:12