Visual Computing Library
|
This module contains all the mathematical functions and utilities used in the library. More...
Classes | |
class | vcl::Distribution< Scalar > |
The Distribution class allows to collect a set of values and then compute some statistics like average, variance, standardDeviation, and percentiles. More... | |
class | vcl::Histogram< ScalarType > |
The Histogram class allows to collect a set of values and then compute some statistics like average, variance, standardDeviation, and percentiles. More... | |
Functions | |
template<typename Scalar > | |
bool | vcl::isDegenerate (Scalar number) |
Checks if a floating point number is degenerate. | |
template<typename Scalar > | |
bool | vcl::epsilonEquals (Scalar n1, Scalar n2, Scalar epsilon=std::numeric_limits< Scalar >::epsilon()) |
Checks if two floating point numbers are equal within an epsilon value. | |
template<typename Scalar > | |
Scalar | vcl::toRad (const Scalar °) |
Converts an angle in degrees to radians. | |
template<typename Scalar > | |
Scalar | vcl::toDeg (const Scalar &rad) |
Converts an angle in radians to degrees. | |
double | vcl::lnOfFactorial (int n) |
Computes and caches the result of the natural logarithm of n! | |
template<Point3Concept PointType> | |
std::vector< PointType > | vcl::sphericalFibonacciPointSet (uint n) |
Returns a vector of n points distributed in a unit sphere. | |
template<typename T > | |
constexpr auto | vcl::min (const T &p1, const T &p2) |
Returns the minimum between the two parameters. | |
template<typename Head , typename... Tail> requires (sizeof...(tail) > 0) | |
constexpr auto | vcl::min (const Head &head0, const Head &head1, const Tail &... tail) |
Returns the minimum between several parameters. | |
template<typename T > | |
constexpr auto | vcl::max (const T &p1, const T &p2) |
Returns the maximum between the two parameters. | |
template<typename Head , typename... Tail> requires (sizeof...(tail) > 0) | |
constexpr auto | vcl::max (const Head &head0, const Head &head1, const Tail &... tail) |
Returns the maximum between several parameters. | |
template<PointConcept PointType> | |
constexpr auto | vcl::min (const PointType &p1, const PointType &p2) |
Returns the minimum between two points. | |
template<PointConcept PointType> | |
constexpr auto | vcl::max (const PointType &p1, const PointType &p2) |
Returns the maximum between two points. | |
int | vcl::poissonRatioOfUniformsInteger (double L, std::mt19937 &gen) |
This subfunction generates a integer with the poisson distribution using the ratio-of-uniforms rejection method (PRUAt). This approach is STABLE even for large L (e.g. it does not suffer from the overflow limit of the classical Knuth implementation) Execution time does not depend on L, except that it matters whether is within the range where ln(n!) is tabulated. | |
int | vcl::poissonRandomNumber (double lambda, std::mt19937 &gen) |
algorithm poisson random number (Knuth): init: Let L ← e^−λ, k ← 0 and p ← 1. do: k ← k + 1. Generate uniform random number u in [0,1] and let p ← p × u. while p > L. return k − 1. | |
template<Point3Concept PointType> | |
PointType | vcl::randomTriangleBarycentricCoordinate (std::mt19937 &gen) |
Generate the barycentric coords of a random point over a triangle, with a uniform distribution over the triangle. It uses the parallelogram folding trick. | |
template<MatrixConcept MatrixType, Point3Concept PointType, typename ScalarType > | |
void | vcl::setTransformMatrixRotation (MatrixType &matrix, PointType axis, const ScalarType &angleRad) |
Given an 3D axis and an angle expressed in radiants, fills the given matrix with a transform matrix that represents the rotation matrix of the given axis/angle. | |
template<MatrixConcept MatrixType, Point3Concept PointType, typename ScalarType > | |
void | vcl::setTransformMatrixRotationDeg (MatrixType &matrix, PointType axis, const ScalarType &angleDeg) |
Given an 3D axis and an angle expressed in degrees, fills the given matrix with a transform matrix that represents the rotation matrix of the given axis/angle. | |
template<MatrixConcept MatrixType, Point3Concept PointType> | |
void | vcl::setTransformMatrixRotation (MatrixType &matrix, const PointType &fromVector, const PointType &toVector) |
Given two 3D vectors, fills the given matrix with a transform matrix that represents the rotation matrix from the first vector to the second vector. | |
template<MatrixConcept MatrixType, Point3Concept PointType, typename ScalarType > | |
MatrixType | vcl::rotationMatrix (const PointType &axis, const ScalarType &angleRad) |
Given an 3D axis and an angle expressed in radiants, returns a transform matrix that represents the rotation matrix of the given axis/angle. | |
template<MatrixConcept MatrixType, Point3Concept PointType, typename ScalarType > | |
MatrixType | vcl::rotationMatrixDeg (const PointType &axis, const ScalarType &angleDeg) |
Given an 3D axis and an angle expressed in degrees, fills the given matrix with a transform matrix that represents the rotation matrix of the given axis/angle. | |
template<MatrixConcept MatrixType, Point3Concept PointType> | |
MatrixType | vcl::rotationMatrix (const PointType &fromVector, const PointType &toVector) |
Given two 3D vectors, returns a transform matrix that represents the rotation matrix from the first vector to the second vector. | |
This module contains all the mathematical functions and utilities used in the library.
This module depends on the Concepts module.
You can access all the concepts of VCLib by including #include <vclib/math.h>
bool vcl::epsilonEquals | ( | Scalar | n1, |
Scalar | n2, | ||
Scalar | epsilon = std::numeric_limits<Scalar>::epsilon() |
||
) |
Checks if two floating point numbers are equal within an epsilon value.
This function returns true if the absolute difference between the two numbers is less than or equal to the epsilon value.
[in] | n1 | the first number to compare |
[in] | n2 | the second number to compare |
[in] | epsilon | the epsilon value to use for the check |
Checks if a floating point number is degenerate.
A floating point number is degenerate if it is infinite or NaN.
[in] | number | the number to check |
Computes and caches the result of the natural logarithm of n!
If n > 1024, uses the Stirling approximation.
[in] | n | the number for which to compute the natural logarithm of the factorial. |
Returns the maximum between several parameters.
Given a list of parameters, this function returns the maximum between all of them.
Example:
[in] | head0 | The first parameter. |
[in] | head1 | The second parameter. |
[in] | tail | The rest of the parameters. |
|
constexpr |
Returns the maximum between two points.
This function returns a point that contains the maximum value between each component of the two input points.
[in] | p1 | The first point. |
[in] | p2 | The second point. |
Returns the maximum between the two parameters.
[in] | p1 | The first parameter. |
[in] | p2 | The second parameter. |
Returns the minimum between several parameters.
Given a list of parameters, this function returns the minimum between all of them.
Example:
[in] | head0 | The first parameter. |
[in] | head1 | The second parameter. |
[in] | tail | The rest of the parameters. |
|
constexpr |
Returns the minimum between two points.
This function returns a point that contains the minimum value between each component of the two input points.
[in] | p1 | The first point. |
[in] | p2 | The second point. |
Returns the minimum between the two parameters.
[in] | p1 | The first parameter. |
[in] | p2 | The second parameter. |
algorithm poisson random number (Knuth): init: Let L ← e^−λ, k ← 0 and p ← 1. do: k ← k + 1. Generate uniform random number u in [0,1] and let p ← p × u. while p > L. return k − 1.
lambda | |
gen |
This subfunction generates a integer with the poisson distribution using the ratio-of-uniforms rejection method (PRUAt). This approach is STABLE even for large L (e.g. it does not suffer from the overflow limit of the classical Knuth implementation) Execution time does not depend on L, except that it matters whether is within the range where ln(n!) is tabulated.
Reference:
E. Stadlober "The ratio of uniforms approach for generating discrete random variates". Journal of Computational and Applied Mathematics, vol. 31, no. 1, 1990, pp. 181-189.
Partially adapted/inspired from some subfunctions of the Agner Fog stocc library ( www.agner.org/random ) Same licensing scheme.
L | |
gen |
PointType vcl::randomTriangleBarycentricCoordinate | ( | std::mt19937 & | gen | ) |
Generate the barycentric coords of a random point over a triangle, with a uniform distribution over the triangle. It uses the parallelogram folding trick.
gen |
MatrixType vcl::rotationMatrix | ( | const PointType & | axis, |
const ScalarType & | angleRad | ||
) |
Given an 3D axis and an angle expressed in radiants, returns a transform matrix that represents the rotation matrix of the given axis/angle.
The MatrixType must be at least a 3x3 matrix having the setIdentity() member function. If the matrix is a higher than 3x3 (e.g. 4x4), only the 3x3 submatrix will be set, leaving the identity values in the other cells of the matrix.
axis | |
angleRad |
MatrixType vcl::rotationMatrix | ( | const PointType & | fromVector, |
const PointType & | toVector | ||
) |
Given two 3D vectors, returns a transform matrix that represents the rotation matrix from the first vector to the second vector.
The MatrixType must be at least a 3x3 matrix having the setIdentity() member function. If the matrix is a higher than 3x3 (e.g. 4x4), only the 3x3 submatrix will be set, leaving the identity values in the other cells of the matrix.
fromVector | |
toVector |
MatrixType vcl::rotationMatrixDeg | ( | const PointType & | axis, |
const ScalarType & | angleDeg | ||
) |
Given an 3D axis and an angle expressed in degrees, fills the given matrix with a transform matrix that represents the rotation matrix of the given axis/angle.
The MatrixType must be at least a 3x3 matrix having the setIdentity() member function. If the matrix is a higher than 3x3 (e.g. 4x4), only the 3x3 submatrix will be set, leaving the identity values in the other cells of the matrix.
axis | |
angleDeg |
void vcl::setTransformMatrixRotation | ( | MatrixType & | matrix, |
const PointType & | fromVector, | ||
const PointType & | toVector | ||
) |
Given two 3D vectors, fills the given matrix with a transform matrix that represents the rotation matrix from the first vector to the second vector.
The given matrix must be at least a 3x3 matrix. If the matrix is a higher than 3x3 (e.g. 4x4), only the 3x3 submatrix will be set, leaving unchanged the other values.
matrix | |
fromVector | |
toVector |
void vcl::setTransformMatrixRotation | ( | MatrixType & | matrix, |
PointType | axis, | ||
const ScalarType & | angleRad | ||
) |
Given an 3D axis and an angle expressed in radiants, fills the given matrix with a transform matrix that represents the rotation matrix of the given axis/angle.
The given matrix must be at least a 3x3 matrix. If the matrix is a higher than 3x3 (e.g. 4x4), only the 3x3 submatrix will be set, leaving unchanged the other values.
matrix | |
axis | |
angleRad |
void vcl::setTransformMatrixRotationDeg | ( | MatrixType & | matrix, |
PointType | axis, | ||
const ScalarType & | angleDeg | ||
) |
Given an 3D axis and an angle expressed in degrees, fills the given matrix with a transform matrix that represents the rotation matrix of the given axis/angle.
The given matrix must be at least a 3x3 matrix. If the matrix is a higher than 3x3 (e.g. 4x4), only the 3x3 submatrix will be set, leaving unchanged the other values.
matrix | |
axis | |
angleDeg |
std::vector< PointType > vcl::sphericalFibonacciPointSet | ( | uint | n | ) |
Returns a vector of n
points distributed in a unit sphere.
This function returns a vector of n
points that are uniformly distributed on a unit sphere, using the Spherical Fibonacci Point Sets algorithm described in the paper "Spherical Fibonacci Mapping" by Benjamin Keinert, Matthias Innmann, Michael Sanger, and Marc Stamminger (TOG 2015).
PointType | The type of the point to generate. This type must satisfy the Point3Concept concept. |
[in] | n | The number of points to generate. |
n
points distributed in a unit sphere. Converts an angle in radians to degrees.
[in] | rad | the angle in radians |