PointCloud2BIM Library  1.0
Library to facilitate the transpormation of point clouds into digital BIM representation
Functions
MathUtils.h File Reference

Set of functions supporting mathematic operations. More...

#include <algorithm>
#include <cmath>
#include <iostream>
#include "BoundingBox.h"
Include dependency graph for MathUtils.h:
This graph shows which files directly or indirectly include this file:

Functions

double det2 (double a1, double b1, double c1, double d1)
 Calculates the determinant of the given 2x2 matrix. More...
 
double det3 (double matrix[3][3])
 Calculates the determinant of the given 3x3 matrix. More...
 
void eig3 (double matrix[3][3], double lambda, double(&result)[3])
 Calculates eigenvector of the given 3x3 matrix for the given eigenvalue. More...
 
void cubicEq (double au, double bu, double cu, double du, double(&result)[3])
 Calculates the solution of a cubic equation ( $ax^3+bx^2+cx+d=0$). More...
 
template<typename T >
void averageD (std::vector< T > &points, double(&v1)[3], double(&averageD))
 Calculates the average coefficient d for the plane ( $ax+bx+cx+d=0$) given by normal vector and interpolated through the given points. More...
 
template<typename T >
void planeFromPoints (std::vector< T > &points, std::vector< int > &indexes, double(&v1)[3], double &averageD)
 Interpolates the plane through the given points. More...
 
template<typename T >
void planeFromPoints (std::vector< T > &points, double(&v1)[3], double(&v2)[3], double(&v3)[3], double &averageD)
 Interpolates the plane through the given points. More...
 
double angleBetweenPlanes (double a1, double b1, double c1, double a2, double b2, double c2)
 Calculates the angle between two planes ( $ax+bx+cx+d=0$). More...
 
double angleBetweenPlanes (double n1[3], double n2[3])
 Calculates the angle between two planes given by normal vectors. More...
 
double dot (double ax, double ay, double az, double bx, double by, double bz)
 Calculates the dot product of two vectors. More...
 
void cross (double(&a)[3], double(&b)[3], double(&result)[3])
 Calculates the cross product of two vectors. More...
 
void normalize (double(&vec)[3])
 Normalizes the given vector. More...
 
template<typename T >
void rotatePointsToLocal (std::vector< T > &points, double(&locx)[3], double(&locy)[3])
 Rotates points in the local coordinate system (z = 0). More...
 
template<typename T >
void rotatePoint (T &pt, double(&v1)[3], double(&v2)[3], double(&v3)[3])
 Rotates point in the local coordinate system given by its base vectors. More...
 
template<typename T >
void rotatePoints (std::vector< T > &points, double(&v1)[3], double(&v2)[3], double(&v3)[3])
 Rotates points in the local coordinate system given by its base vectors. More...
 
template<typename T >
void moveCSorigin (std::vector< T > &points, T O)
 Recalculates the coordinates of the points when the new origin of the coordinate system is set. More...
 
template<typename T >
void moveBackCSorigin (std::vector< T > &points, T O)
 Recalculates the coordinates of the points when the origin of the coordinate system is reset from the given O to (0, 0, 0). More...
 
template<typename T >
void giveLocalCS (std::vector< T > &points, double(&locx)[3], double(&locy)[3], double(&locz)[3])
 Calculates local coordinate system of the plane defined by the given points. More...
 
void giveLtoGVectorsFromLocalCS (double(&locx)[3], double(&locy)[3], double(&locz)[3], double(&l2g1)[3], double(&l2g2)[3], double(&l2g3)[3])
 Calculates the global-to-local (G2L) transformation vectors to local-to-global (L2G) transformation vectors. More...
 
template<typename T >
double giveAverageCoord (std::vector< T > &points, int cIndex)
 Calculates the average coordinate of the given points. More...
 
template<typename T >
void projectPointsToXYPlane (std::vector< T > &points)
 Sets the z-coordinate of the given points to the zero. More...
 

Detailed Description

Set of functions supporting mathematic operations.

Function Documentation

double angleBetweenPlanes ( double  a1,
double  b1,
double  c1,
double  a2,
double  b2,
double  c2 
)

Calculates the angle between two planes ( $ax+bx+cx+d=0$).

Parameters
a1Coefficient a of the first plane
b1Coefficient b of the first plane
c1Coefficient c of the first plane
a1Coefficient a of the second plane
b1Coefficient b of the second plane
c1Coefficient c of the second plane
Returns
Angle between the planes
double angleBetweenPlanes ( double  n1[3],
double  n2[3] 
)

Calculates the angle between two planes given by normal vectors.

Parameters
n1Normal vector of the first plane
n2Normal vector of the second plane
Returns
Angle between the planes
template<typename T >
void averageD ( std::vector< T > &  points,
double(&)  v1[3],
double &  averageD 
)

Calculates the average coefficient d for the plane ( $ax+bx+cx+d=0$) given by normal vector and interpolated through the given points.

Parameters
pointsPlane points
v1Plane normal vector
averageDReturn parameter storing the calculated coefficient
void cross ( double(&)  a[3],
double(&)  b[3],
double(&)  result[3] 
)

Calculates the cross product of two vectors.

Parameters
aThe first vector
bThe second vector
resultReturn parameter storing the resulting cross product
void cubicEq ( double  au,
double  bu,
double  cu,
double  du,
double(&)  result[3] 
)

Calculates the solution of a cubic equation ( $ax^3+bx^2+cx+d=0$).

Parameters
auCoefficient a
buCoefficient b
cuCoefficient c
duCoefficient d
resultReturn parameter storing the calculated solution
double det2 ( double  a1,
double  b1,
double  c1,
double  d1 
)

Calculates the determinant of the given 2x2 matrix.

Parameters
a1Matrix element (1,1)
b1Matrix element (1,2)
c1Matrix element (2,1)
d1Matrix element (2,2)
Returns
Determinant
double det3 ( double  matrix[3][3])

Calculates the determinant of the given 3x3 matrix.

Parameters
matrix3x3 matrix
Returns
Determinant
double dot ( double  ax,
double  ay,
double  az,
double  bx,
double  by,
double  bz 
)

Calculates the dot product of two vectors.

Parameters
axX component of the first vector
ayY component of the first vector
azZ component of the first vector
bxX component of the second vector
byY component of the second vector
bzZ component of the second vector
Returns
Resulting dot product
void eig3 ( double  matrix[3][3],
double  lambda,
double(&)  result[3] 
)

Calculates eigenvector of the given 3x3 matrix for the given eigenvalue.

Parameters
matrix3x3 matrix
lambdaEigenvalue
resultReturn parameter storing the calculated eigenvector
template<typename T >
double giveAverageCoord ( std::vector< T > &  points,
int  cIndex 
)

Calculates the average coordinate of the given points.

Parameters
pointsThe points for calculation of the average coordinate
indexIndex specifying which coordinate to calculate (0~x, 1~y, 2~z)
Returns
The average coordinate calculated
template<typename T >
void giveLocalCS ( std::vector< T > &  points,
double(&)  locx[3],
double(&)  locy[3],
double(&)  locz[3] 
)

Calculates local coordinate system of the plane defined by the given points.

Parameters
pointsPoints defining the plane for which to calculate the local coordinate system
locxReturn parameter storing local x-axis (in plane, horizontal)
locyReturn parameter storing local y-axis (in plane, vertical)
loczReturn parameter storing local z-axis (normal vector)
void giveLtoGVectorsFromLocalCS ( double(&)  locx[3],
double(&)  locy[3],
double(&)  locz[3],
double(&)  l2g1[3],
double(&)  l2g2[3],
double(&)  l2g3[3] 
)

Calculates the global-to-local (G2L) transformation vectors to local-to-global (L2G) transformation vectors.

Parameters
locxThe first G2L transformation vector
locyThe second G2L transformation vector
loczThe third G2L transformation vector
l2g1In-out parameter storing the first L2G transformation vector $\{locx(1), locy(1), locz(1)\}$
l2g1In-out parameter storing the second L2G transformation vector $\{locx(2), locy(2), locz(2)\}$
l2g1In-out parameter storing the third L2G transformation vector $\{locx(3), locy(3), locz(3)\}$
template<typename T >
void moveBackCSorigin ( std::vector< T > &  points,
O 
)

Recalculates the coordinates of the points when the origin of the coordinate system is reset from the given O to (0, 0, 0).

Parameters
ptIn-Out parameter storing the points to be transformed
OActual origin coordinates
template<typename T >
void moveCSorigin ( std::vector< T > &  points,
O 
)

Recalculates the coordinates of the points when the new origin of the coordinate system is set.

Parameters
ptIn-Out parameter storing the points to be transformed
ONew origin coordinates
void normalize ( double(&)  vec[3])

Normalizes the given vector.

Parameters
vecIn-Out parameter storing the vector to be normalized
template<typename T >
void planeFromPoints ( std::vector< T > &  points,
std::vector< int > &  indexes,
double(&)  v1[3],
double &  averageD 
)

Interpolates the plane through the given points.

Parameters
pointsPoints for the calculation
indexesIndexes specifying which points to use for the plane calculation
v1Return parametr storing the normal vector of the plane
averageDCoefficient d of the plane equation ( $ax+bx+cx+d=0$)
template<typename T >
void planeFromPoints ( std::vector< T > &  points,
double(&)  v1[3],
double(&)  v2[3],
double(&)  v3[3],
double &  averageD 
)

Interpolates the plane through the given points.

Parameters
pointsPoints through which to interpolate the plane
v1Return parametr storing the normal vector of the plane
v2Return parametr storing the first in-plane vector
v3Return parametr storing the second in-plane vector
averageDCoefficient d of the plane equation ( $ax+bx+cx+d=0$)
template<typename T >
void projectPointsToXYPlane ( std::vector< T > &  points)

Sets the z-coordinate of the given points to the zero.

Parameters
pointsIn-Out parameter storing the points to be projected
template<typename T >
void rotatePoint ( T &  pt,
double(&)  v1[3],
double(&)  v2[3],
double(&)  v3[3] 
)

Rotates point in the local coordinate system given by its base vectors.

Parameters
ptIn-Out parameter storing the point to be rotated
v1The first base vector of the local coordinate system
v2The second base vector of the local coordinate system
v3The third base vector of the local coordinate system
template<typename T >
void rotatePoints ( std::vector< T > &  points,
double(&)  v1[3],
double(&)  v2[3],
double(&)  v3[3] 
)

Rotates points in the local coordinate system given by its base vectors.

Parameters
ptIn-Out parameter storing the points to be rotated
v1The first base vector of the local coordinate system
v2The second base vector of the local coordinate system
v3The third base vector of the local coordinate system
template<typename T >
void rotatePointsToLocal ( std::vector< T > &  points,
double(&)  locx[3],
double(&)  locy[3] 
)

Rotates points in the local coordinate system (z = 0).

Parameters
pointsIn-Out parameter storing the points to be rotated
locxLocal x vector
locyLocal y vector