Thea
Thea::Math Namespace Reference

Mathematical functions. More...

## Functions

int binaryTreeDepth (intx num_elems, int max_elems_in_leaf, Real split_ratio=0.5)
Get the estimated depth of a binary tree with a given number of elements, assuming an upper bound on the number of elements in each leaf, and the average split ratio at each node. More...

int ceilLog2 (uint32 i)
Compute the ceiling of the logarithm of an integer, to the base 2. More...

template<typename T , typename U , typename V >
clamp (T const &x, U const &lo, V const &hi)
Clamp a number to lie in the range [lo, hi] (inclusive). More...

template<typename T , typename S >
cspline (T const &a, T const &da, T const &b, T const &db, S const &s)
Hermite interpolation, given two points a and b, the associated tangents da and db at these points, and a parameter s in [0, 1]. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Convert an angle from degrees to radians. More...

template<typename T >
int eigenSolve (Matrix< 2, 2, T > const &m, T *eigenvalues, Vector< 2, T > *eigenvectors, T const &tol=-1)
Solve for the real eigenvalues and eigenvectors of a 2x2 matrix. More...

template<typename T >
eps ()
An "epsilon" threshold for comparing a number to zero. More...

template<typename T >
eps (T const &a, T const &b)
An "epsilon" threshold for comparing two numbers a and b. More...

float fastArcCos (float c)
Fast approximation of inverse cosine using a lookup table. More...

float fastArcSin (float s)
Fast approximation of inverse sine using a lookup table. More...

float fastArcTan (float t)
Fast approximation of inverse tangent using a lookup table. More...

float fastArcTan2 (float dy, float dx)
Fast approximation of atan2 using a lookup table. More...

Fast approximation of cosine function using a lookup table, requires radians in [0, 2 pi]. More...

float32 fastLog2 (float32 f)
Fast approximation of logarithm to the base 2. More...

float fastMinusExp (float x)
Computes a fast approximation to exp(-x). More...

float fastMinusExp01 (float x)
Computes a fast approximation to exp(-x) for 0 <= x <= 1. More...

float32 fastRsq (float32 x)
A fast approximation to 1 / sqrt(x). More...

double fastRsq (double x)
A fast approximation to 1 / sqrt(x) (currently no faster than 1 / std::sqrt). More...

Fast approximation of sine function using a lookup table, requires radians in [0, 2 pi]. More...

template<typename T >
fastSqrt (T const &x)
Fast approximation of square root. More...

Fast approximation of tangent function using a lookup table, requires radians in [0, 2 pi]. More...

int floorLog2 (uint32 i)
Compute the floor of the logarithm of an integer, to the base 2. More...

template<typename T >
bool fuzzyEq (T const &a, T const &b, T const &tol)
Check if two numbers are approximately equal, with a given tolerance. More...

template<typename T >
bool fuzzyEq (T const &a, T const &b)
Check if two numbers are approximately equal, with default tolerance. More...

template<typename T >
bool fuzzyGe (T const &a, T const &b, T const &tol)
Check if a is greater than or approximately equal to b, with a given tolerance. More...

template<typename T >
bool fuzzyGe (T const &a, T const &b)
Check if a is greater than or approximately equal to b, with default tolerance. More...

template<typename T >
bool fuzzyGt (T const &a, T const &b, T const &tol)
Check if a is strictly greater than b by at least a minimum value, with default tolerance. More...

template<typename T >
bool fuzzyGt (T const &a, T const &b)
Check if a is strictly greater than b by at least a minimum value, with default tolerance. More...

template<typename T >
bool fuzzyLe (T const &a, T const &b, T const &tol)
Check if a is less than or approximately equal to b, with a given tolerance. More...

template<typename T >
bool fuzzyLe (T const &a, T const &b)
Check if a is less than or approximately equal to b, with default tolerance. More...

template<typename T >
bool fuzzyLt (T const &a, T const &b, T const &tol)
Check if a is strictly less than b by at least a minimum value, with default tolerance. More...

template<typename T >
bool fuzzyLt (T const &a, T const &b)
Check if a is strictly less than b by at least a minimum value, with default tolerance. More...

template<typename T >
bool fuzzyNe (T const &a, T const &b, T const &tol)
Check if two numbers are not approximately equal, with a given tolerance. More...

template<typename T >
bool fuzzyNe (T const &a, T const &b)
Check if two numbers are not approximately equal, with default tolerance. More...

template<typename Derived , typename OutT >
void getElementsColumnMajor (Eigen::MatrixBase< Derived > const &m, OutT *buf)
Get the elements of a matrix in column-major order. More...

template<typename Derived , typename OutT >
void getElementsRowMajor (Eigen::MatrixBase< Derived > const &m, OutT *buf)
Get the elements of a matrix in row-major order. More...

double halfPi ()
The constant Pi / 2. More...

int highestBit (uint32 x)
Get the highest non-zero bit of a 32-bit unsigned integer. More...

template<typename T , int N, int O1, int R1, int C1, int O2, int R2, int C2>
Eigen::Matrix< T, N-1, 1, O2, R2, C2 > hmul (Eigen::Matrix< T, N, N, O1, R1, C1 > const &m, Eigen::Matrix< T, N-1, 1, O2, R2, C2 > const &v)
Convenience function to multiply a 4x4 matrix by a 3-vector, by converting to homogeneous coordinates, multiplying, and converting back. More...

template<class T >
inf ()
Representation of infinity. More...

template<class T >
bool isFinite (T const &t)
Check if a number is finite (neither infinity nor NaN). More...

template<class T >
bool isInfinite (T const &t)
Check if a number represents (positive or negative) infinity. More...

template<class T >
bool isNaN (T const &t)
Check if a number represents NaN ("not a number", for instance the result of 0/0). More...

bool isPowerOf2 (uintx i)
Very fast test to check if a number is a power of 2 or not. More...

template<typename MatrixT >
bool isSquare (MatrixT const &m)
Check if a matrix is square, that is, has the same number of rows and columns. More...

template<typename T , typename S >
lerp (T const &a, T const &b, S const &f)
Returns a + (b - a) * f. More...

template<typename MatrixT , typename IDenseMatrixT , typename std::enable_if< std::is_base_of< IDenseMatrix< typename IDenseMatrixT::value_type >, IDenseMatrixT >::value &&std::is_same< typename IDenseMatrixT::value_type, typename MatrixT::value_type >::value &&std::is_const< IDenseMatrixT >::value==std::is_const< MatrixT >::value, int >::type = 0>
Eigen::Map< MatrixT > mapTo (IDenseMatrixT &m)
Convenience function for interpreting raw buffers wrapped in IDenseMatrix objects as Eigen::Map objects. More...

template<typename Derived >
Eigen::Index maxAbsAxis (Eigen::MatrixBase< Derived > const &v)
Get the coordinate of a vector with the largest absolute value. More...

template<typename Derived >
Eigen::Index maxAxis (Eigen::MatrixBase< Derived > const &v)
Get the coordinate of a vector with the largest value. More...

template<typename Derived >
Eigen::Index minAbsAxis (Eigen::MatrixBase< Derived > const &v)
Get the coordinate of a vector with the least absolute value. More...

template<typename Derived >
Eigen::Index minAxis (Eigen::MatrixBase< Derived > const &v)
Get the coordinate of a vector with the least value. More...

template<class T >
nan ()
Representation of NaN (not-a-number). More...

template<int N, typename T = Real>
Vector< N, T > oneCold (int coord)
Get the one-cold vector with all entries 1 except a single entry which is 0. More...

template<typename Derived >
void oneCold (int coord, Eigen::MatrixBase< Derived > &v)
Get the one-cold vector with all entries 1 except a single entry which is 0. More...

template<int N, typename T = Real>
Vector< N, T > oneHot (int coord)
Get the one-hot vector with all entries 0 except a single entry which is 1. More...

template<typename Derived >
void oneHot (int coord, Eigen::MatrixBase< Derived > &v)
Get the one-hot vector with all entries 0 except a single entry which is 1. More...

template<typename T >
Vector< 2, T > orthogonalDirection (Vector< 2, T > const &v)
Given a 2D vector v, get the unit vector `u` perpendicular to it, forming an orthonormal right-handed basis `(u, v.normalized())`. More...

template<typename T >
Vector< 3, T > orthogonalDirection (Vector< 3, T > const &v)
Given a 3D vector, get an arbitrary unit vector perpendicular to it. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Matrix< 4, 4, T > orthogonalProjection (T const &left, T const &right, T const &bottom, T const &top, T const &nearval, T const &farval, bool y_increases_upwards=true)
Constructs an orthogonal 3D projection matrix from the given parameters. More...

template<typename T >
Vector< 2, T > orthogonalVector (Vector< 2, T > const &v)
Given a 2D vector v, get the vector `u` perpendicular to it and of the same length, forming a right-handed basis `(u, v)`. More...

template<typename T >
Matrix< 3, 3, T > orthonormalBasis (Vector< 3, T > const &w)
Given a 3D vector w (need not be unit length), construct a 3x3 rotation matrix whose last column is the normalized direction of w. More...

template<typename T >
Matrix< 3, 3, T > orthonormalBasis (Vector< 3, T > const &u, Vector< 3, T > const &v, Vector< 3, T > const &w)
Given three 3D vectors u, v and w (need not be unit length), construct a 3x3 rotation matrix whose last column is the normalized direction of w, and whose first and second columns are "close to" the normalized directions of u and v respectively. More...

template<typename T >
Matrix< 3, 3, T > orthonormalBasis (Matrix< 3, 3, T > const &m)
Given an arbitrary input 3x3 matrix m, construct another 3x3 rotation matrix whose last column is the normalized direction of the last column of m, and whose first and second columns are "close to" the normalized directions of the first and second columns respectively of m. More...

int padPeriodic (int i, int period)
Pad an integer to a multiple of a period. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Matrix< 4, 4, T > perspectiveProjection (T const &left, T const &right, T const &bottom, T const &top, T const &nearval, T const &farval, bool y_increases_upwards=true)
Constructs a 3D perspective projection matrix from the given parameters. More...

double pi ()
The constant Pi. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Convert an angle from radians to degrees. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Matrix< 2, 2, T > rotation (T const &radians)
Matrix to rotate a 2D vector about the origin by an angle (in radians). More...

template<typename T >
Matrix< 3, 3, T > rotationArc (Vector< 3, T > const &start_dir, Vector< 3, T > const &end_dir, bool normalize_dirs=true)
Return the matrix corresponding to the rotation from one direction vector to another. More...

template<typename T >
Quaternion< T > rotationArcQuat (Vector< 3, T > const &start_dir, Vector< 3, T > const &end_dir, bool normalize_dirs=true)
Return the quaternion corresponding to the rotation from one direction vector to another. More...

template<typename T >
Matrix< 3, 3, T > rotationAxisAngle (Vector< 3, T > const &axis, T const &radians)
Rotate around the given 3D axis (need not be a unit vector) by a given angle. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Rotate about the Z axis by the roll angle, then the Y axis by the pitch angle, and finally the X axis by the yaw angle. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Rotate about the Y axis by the roll angle, then the Z axis by the pitch angle, and finally the X axis by the yaw angle. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Rotate about the Z axis by the roll angle, then the X axis by the pitch angle, and finally the Y axis by the yaw angle. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Rotate about the X axis by the roll angle, then the Z axis by the pitch angle, and finally the Y axis by the yaw angle. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Rotate about the Y axis by the roll angle, then the X axis by the pitch angle, and finally the Z axis by the yaw angle. More...

template<typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Rotate about the X axis by the roll angle, then the Y axis by the pitch angle, and finally the Z axis by the yaw angle. More...

float round (float x)
Round a real number to the nearest integer using the lrintf() routine. More...

double round (double x)
Round a real number to the nearest integer using the lrint() routine. More...

template<int N, typename T >
Matrix< N, N, T > scaling (Vector< N, T > const &s)
Matrix to scale a point by the corresponding scaling parameter along each dimension. More...

template<int N, typename T , typename std::enable_if< !std::is_integral< T >::value >::type * = nullptr>
Matrix< N, N, T > scaling (T const &s)
Matrix to uniformaly scale a point by a scaling factor s. More...

template<typename T >
int sign (T const &x)
Get the sign of a number. More...

int solveCubic (double c0, double c1, double c2, double c3, double *roots)
Real roots of cubic equation c0 + c1 * x + c2 * x^2 + c3 * x^3 = 0. More...

int solveLinear (double c0, double c1, double *root)
Root of linear equation c0 + c1 * x = 0. More...

int solveQuadratic (double c0, double c1, double c2, double *roots)
Distinct real roots x1, x2 of quadratic equation c0 + c1 * x + c2 * x^2 = 0. More...

int solveQuartic (double c0, double c1, double c2, double c3, double c4, double *roots)
Real roots of quartic equation c0 + c1 * x + c2 * x^2 + c3 * x^3 + c4 * x^4 = 0. More...

template<typename T >
square (T const &x)
Compute the square of a value. More...

double twoPi ()
The constant 2 * Pi. More...

template<typename MatrixT >
SparseMatrixWrapper< MatrixT > wrapMatrix (Eigen::SparseMatrixBase< MatrixT > &m)
Convenience function for creating a MatrixWrapper object from a matrix reference, without needing to specify template parameters. More...

template<typename MatrixT >
SparseMatrixWrapper< MatrixT > wrapMatrix (Eigen::SparseMatrixBase< MatrixT > *m)
Convenience function for creating a MatrixWrapper object from a matrix pointer, without needing to specify template parameters. More...

template<typename MatrixT >
MatrixWrapper< MatrixT > wrapMatrix (Eigen::MatrixBase< MatrixT > &m)
Convenience function for creating a MatrixWrapper object from a matrix reference, without needing to specify template parameters. More...

template<typename MatrixT >
MatrixWrapper< MatrixT > wrapMatrix (Eigen::MatrixBase< MatrixT > *m)
Convenience function for creating a MatrixWrapper object from a matrix pointer, without needing to specify template parameters. More...

## Detailed Description

Mathematical functions.

## Function Documentation

 int binaryTreeDepth ( intx num_elems, int max_elems_in_leaf, Real split_ratio = `0.5` )

Get the estimated depth of a binary tree with a given number of elements, assuming an upper bound on the number of elements in each leaf, and the average split ratio at each node.

Parameters
 num_elems The number of elements in the tree. max_elems_in_leaf The maximum number of elements allowed in each leaf. split_ratio The average splitting ratio at a node, expressed as the fraction of elements in the larger child of the node (0.5 is a perfectly fair split). Must be in the range (0, 1).

Definition at line 23 of file Math.cpp.

 int Thea::Math::ceilLog2 ( uint32 i )

Compute the ceiling of the logarithm of an integer, to the base 2.

Returns -1 if the integer is 0.

Definition at line 139 of file Math.hpp.

 T Thea::Math::clamp ( T const & x, U const & lo, V const & hi )

Clamp a number to lie in the range [lo, hi] (inclusive).

Definition at line 328 of file Math.hpp.

 T Thea::Math::cspline ( T const & a, T const & da, T const & b, T const & db, S const & s )

Hermite interpolation, given two points a and b, the associated tangents da and db at these points, and a parameter s in [0, 1].

Definition at line 528 of file Math.hpp.

 T Thea::Math::degreesToRadians ( T const & deg )

Convert an angle from degrees to radians.

Definition at line 356 of file Math.hpp.

 int Thea::Math::eigenSolve ( Matrix< 2, 2, T > const & m, T * eigenvalues, Vector< 2, T > * eigenvectors, T const & tol = `-1` )

Solve for the real eigenvalues and eigenvectors of a 2x2 matrix.

Parameters
 m The matrix whose eigenvalues/vectors will be found. eigenvalues Used to return the eigenvalues of the matrix. Must be preallocated to at least 2 elements. eigenvectors Used to return the eigenvectors of the matrix. Must be preallocated to at least 2 elements. tol Numerical tolerance, negative for default.
Returns
The number of real eigenvalues found.

Definition at line 632 of file MatrixUtil.hpp.

 T Thea::Math::eps ( )

An "epsilon" threshold for comparing a number to zero.

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Definition at line 189 of file Math.hpp.

 T Thea::Math::eps ( T const & a, T const & b )

An "epsilon" threshold for comparing two numbers a and b.

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

Definition at line 198 of file Math.hpp.

 float Thea::Math::fastArcCos ( float c )

Fast approximation of inverse cosine using a lookup table.

Return value is in radians, range [0, pi] (like std::acos).

Definition at line 420 of file Math.hpp.

 float Thea::Math::fastArcSin ( float s )

Fast approximation of inverse sine using a lookup table.

Return value is in radians, range [-pi/2, pi/2] (like std::asin).

Definition at line 407 of file Math.hpp.

 float Thea::Math::fastArcTan ( float t )

Fast approximation of inverse tangent using a lookup table.

Return value is in radians, range [-pi/2, pi/2] (like std::atan).

Definition at line 437 of file Math.hpp.

 float Thea::Math::fastArcTan2 ( float dy, float dx )

Fast approximation of atan2 using a lookup table.

Return value is in radians, range [-pi, pi] (like std::atan2). Both arguments should not be zero.

Definition at line 459 of file Math.hpp.

 float Thea::Math::fastCos ( float radians )

Fast approximation of cosine function using a lookup table, requires radians in [0, 2 pi].

Definition at line 398 of file Math.hpp.

 float32 Thea::Math::fastLog2 ( float32 f )

Fast approximation of logarithm to the base 2.

Definition at line 147 of file Math.hpp.

 float Thea::Math::fastMinusExp ( float x )

Computes a fast approximation to exp(-x).

Definition at line 504 of file Math.hpp.

 float Thea::Math::fastMinusExp01 ( float x )

Computes a fast approximation to exp(-x) for 0 <= x <= 1.

Definition at line 511 of file Math.hpp.

 float32 Thea::Math::fastRsq ( float32 x )

A fast approximation to 1 / sqrt(x).

Definition at line 259 of file Math.hpp.

 double Thea::Math::fastRsq ( double x )

A fast approximation to 1 / sqrt(x) (currently no faster than 1 / std::sqrt).

Definition at line 277 of file Math.hpp.

 float Thea::Math::fastSin ( float radians )

Fast approximation of sine function using a lookup table, requires radians in [0, 2 pi].

Definition at line 395 of file Math.hpp.

 T Thea::Math::fastSqrt ( T const & x )

Fast approximation of square root.

Definition at line 285 of file Math.hpp.

 float Thea::Math::fastTan ( float radians )

Fast approximation of tangent function using a lookup table, requires radians in [0, 2 pi].

Definition at line 401 of file Math.hpp.

 int Thea::Math::floorLog2 ( uint32 i )

Compute the floor of the logarithm of an integer, to the base 2.

Returns -1 if the integer is 0.

Definition at line 132 of file Math.hpp.

 bool Thea::Math::fuzzyEq ( T const & a, T const & b, T const & tol )

Check if two numbers are approximately equal, with a given tolerance.

Definition at line 210 of file Math.hpp.

 bool Thea::Math::fuzzyEq ( T const & a, T const & b )

Check if two numbers are approximately equal, with default tolerance.

Definition at line 213 of file Math.hpp.

 bool Thea::Math::fuzzyGe ( T const & a, T const & b, T const & tol )

Check if a is greater than or approximately equal to b, with a given tolerance.

Definition at line 234 of file Math.hpp.

 bool Thea::Math::fuzzyGe ( T const & a, T const & b )

Check if a is greater than or approximately equal to b, with default tolerance.

Definition at line 237 of file Math.hpp.

 bool Thea::Math::fuzzyGt ( T const & a, T const & b, T const & tol )

Check if a is strictly greater than b by at least a minimum value, with default tolerance.

Guaranteed false if a <= b, possibly false if a > b.

Definition at line 225 of file Math.hpp.

 bool Thea::Math::fuzzyGt ( T const & a, T const & b )

Check if a is strictly greater than b by at least a minimum value, with default tolerance.

Guaranteed false if a <= b, possibly false if a > b.

Definition at line 231 of file Math.hpp.

 bool Thea::Math::fuzzyLe ( T const & a, T const & b, T const & tol )

Check if a is less than or approximately equal to b, with a given tolerance.

Definition at line 252 of file Math.hpp.

 bool Thea::Math::fuzzyLe ( T const & a, T const & b )

Check if a is less than or approximately equal to b, with default tolerance.

Definition at line 255 of file Math.hpp.

 bool Thea::Math::fuzzyLt ( T const & a, T const & b, T const & tol )

Check if a is strictly less than b by at least a minimum value, with default tolerance.

Guaranteed false if a >= b, possibly false if a < b.

Definition at line 243 of file Math.hpp.

 bool Thea::Math::fuzzyLt ( T const & a, T const & b )

Check if a is strictly less than b by at least a minimum value, with default tolerance.

Guaranteed false if a >= b, possibly false if a < b.

Definition at line 249 of file Math.hpp.

 bool Thea::Math::fuzzyNe ( T const & a, T const & b, T const & tol )

Check if two numbers are not approximately equal, with a given tolerance.

Definition at line 216 of file Math.hpp.

 bool Thea::Math::fuzzyNe ( T const & a, T const & b )

Check if two numbers are not approximately equal, with default tolerance.

Definition at line 219 of file Math.hpp.

 void Thea::Math::getElementsColumnMajor ( Eigen::MatrixBase< Derived > const & m, OutT * buf )

Get the elements of a matrix in column-major order.

Definition at line 62 of file MatrixUtil.hpp.

 void Thea::Math::getElementsRowMajor ( Eigen::MatrixBase< Derived > const & m, OutT * buf )

Get the elements of a matrix in row-major order.

Definition at line 51 of file MatrixUtil.hpp.

 double Thea::Math::halfPi ( )

The constant Pi / 2.

Definition at line 299 of file Math.hpp.

 int Thea::Math::highestBit ( uint32 x )

Get the highest non-zero bit of a 32-bit unsigned integer.

Returns -1 if the integer is 0.

Definition at line 104 of file Math.hpp.

 Eigen::Matrix Thea::Math::hmul ( Eigen::Matrix< T, N, N, O1, R1, C1 > const & m, Eigen::Matrix< T, N-1, 1, O2, R2, C2 > const & v )

Convenience function to multiply a 4x4 matrix by a 3-vector, by converting to homogeneous coordinates, multiplying, and converting back.

Definition at line 122 of file MatrixUtil.hpp.

 T Thea::Math::inf ( )

Representation of infinity.

Don't compare against this value directly.

Definition at line 179 of file Math.hpp.

 bool Thea::Math::isFinite ( T const & t )

Check if a number is finite (neither infinity nor NaN).

Definition at line 170 of file Math.hpp.

 bool Thea::Math::isInfinite ( T const & t )

Check if a number represents (positive or negative) infinity.

Definition at line 173 of file Math.hpp.

 bool Thea::Math::isNaN ( T const & t )

Check if a number represents NaN ("not a number", for instance the result of 0/0).

Definition at line 176 of file Math.hpp.

 bool Thea::Math::isPowerOf2 ( uintx i )

Very fast test to check if a number is a power of 2 or not.

Definition at line 157 of file Math.hpp.

 bool Thea::Math::isSquare ( MatrixT const & m )

Check if a matrix is square, that is, has the same number of rows and columns.

Definition at line 43 of file MatrixUtil.hpp.

 T Thea::Math::lerp ( T const & a, T const & b, S const & f )

Returns a + (b - a) * f.

Definition at line 348 of file Math.hpp.

 Eigen::Map Thea::Math::mapTo ( IDenseMatrixT & m )

Convenience function for interpreting raw buffers wrapped in IDenseMatrix objects as Eigen::Map objects.

It avoids having to pass the matrix dimensions separately as required by the Eigen::Map constructors for non-fixed-size matrices. Note that the function signature is equivalent to:

Eigen::Map<MatrixT const> mapTo(IDenseMatrix<ScalarT> const & m);

for const-qualified matrix types, and

Eigen::Map<MatrixT> mapTo(IDenseMatrix<ScalarT> & m);

for non-const types.

E.g.:

IDenseMatrix<Real> const * d = <... get a matrix e.g. from across a DLL boundary ...>
auto m = Math::mapTo<MatrixX<> const>(*d);
... treat m as a normal Eigen dynamic-size matrix ...

Definition at line 84 of file IDenseMatrix.hpp.

 Eigen::Index Thea::Math::maxAbsAxis ( Eigen::MatrixBase< Derived > const & v )

Get the coordinate of a vector with the largest absolute value.

The behavior is undefined if v is not a (row or column) vector.

Definition at line 109 of file MatrixUtil.hpp.

 Eigen::Index Thea::Math::maxAxis ( Eigen::MatrixBase< Derived > const & v )

Get the coordinate of a vector with the largest value.

The behavior is undefined if v is not a (row or column) vector.

Definition at line 83 of file MatrixUtil.hpp.

 Eigen::Index Thea::Math::minAbsAxis ( Eigen::MatrixBase< Derived > const & v )

Get the coordinate of a vector with the least absolute value.

The behavior is undefined if v is not a (row or column) vector.

Definition at line 96 of file MatrixUtil.hpp.

 Eigen::Index Thea::Math::minAxis ( Eigen::MatrixBase< Derived > const & v )

Get the coordinate of a vector with the least value.

The behavior is undefined if v is not a (row or column) vector.

Definition at line 73 of file MatrixUtil.hpp.

 T Thea::Math::nan ( )

Representation of NaN (not-a-number).

Don't compare against this value directly.

Definition at line 182 of file Math.hpp.

 Vector Thea::Math::oneCold ( int coord )

Get the one-cold vector with all entries 1 except a single entry which is 0.

Values of the CoordinateAxis enum may be used as arguments. This version creates and returns a fixed-length vector.

Definition at line 154 of file MatrixUtil.hpp.

 void Thea::Math::oneCold ( int coord, Eigen::MatrixBase< Derived > & v )

Get the one-cold vector with all entries 1 except a single entry which is 0.

Values of the CoordinateAxis enum may be used as arguments. This version initializes a provided vector to be one-cold.

Definition at line 169 of file MatrixUtil.hpp.

 Vector Thea::Math::oneHot ( int coord )

Get the one-hot vector with all entries 0 except a single entry which is 1.

Values of the CoordinateAxis enum may be used as arguments. This version returns a fixed-length vector, and is equivalent to `Vector<N, T>::Unit(coord)`.

Definition at line 132 of file MatrixUtil.hpp.

 void Thea::Math::oneHot ( int coord, Eigen::MatrixBase< Derived > & v )

Get the one-hot vector with all entries 0 except a single entry which is 1.

Values of the CoordinateAxis enum may be used as arguments. This version initializes a provided vector to be one-hot.

Definition at line 140 of file MatrixUtil.hpp.

 Vector<2, T> Thea::Math::orthogonalDirection ( Vector< 2, T > const & v )

Given a 2D vector v, get the unit vector `u` perpendicular to it, forming an orthonormal right-handed basis `(u, v.normalized())`.

In other words, if v is the Y axis of the local frame, then the function returns the unit X axis.

Definition at line 195 of file MatrixUtil.hpp.

 Vector<3, T> Thea::Math::orthogonalDirection ( Vector< 3, T > const & v )

Given a 3D vector, get an arbitrary unit vector perpendicular to it.

Definition at line 203 of file MatrixUtil.hpp.

 Matrix<4, 4, T> Thea::Math::orthogonalProjection ( T const & left, T const & right, T const & bottom, T const & top, T const & nearval, T const & farval, bool y_increases_upwards = `true` )

Constructs an orthogonal 3D projection matrix from the given parameters.

nearval and farval are the negative of the near and far plane Z values (to follow OpenGL conventions). Set y_increases_upwards to false if Y increases downwards instead, e.g. for screen pixel space.

Definition at line 554 of file MatrixUtil.hpp.

 Vector<2, T> Thea::Math::orthogonalVector ( Vector< 2, T > const & v )

Given a 2D vector v, get the vector `u` perpendicular to it and of the same length, forming a right-handed basis `(u, v)`.

Definition at line 183 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::orthonormalBasis ( Vector< 3, T > const & w )

Given a 3D vector w (need not be unit length), construct a 3x3 rotation matrix whose last column is the normalized direction of w.

The first two columns are arbitrarily chosen to be unit vectors perpendicular to each other and to w. The columns define a local right-handed coordinate frame with Z axis along w, and X and Y axes along the first and second columns respectively (X x Y == Z).

Definition at line 219 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::orthonormalBasis ( Vector< 3, T > const & u, Vector< 3, T > const & v, Vector< 3, T > const & w )

Given three 3D vectors u, v and w (need not be unit length), construct a 3x3 rotation matrix whose last column is the normalized direction of w, and whose first and second columns are "close to" the normalized directions of u and v respectively.

The columns of the returned matrix will form a right-handed orthonormal basis. If the input approximates a left-handed basis, one of the first two columns of the returned matrix will oppose the corresponding input vector.

Definition at line 237 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::orthonormalBasis ( Matrix< 3, 3, T > const & m )

Given an arbitrary input 3x3 matrix m, construct another 3x3 rotation matrix whose last column is the normalized direction of the last column of m, and whose first and second columns are "close to" the normalized directions of the first and second columns respectively of m.

The columns of the returned matrix will form a right-handed orthonormal basis. If the input approximates a left-handed basis, one of the first two columns of the returned matrix will oppose the corresponding input column.

Definition at line 256 of file MatrixUtil.hpp.

 int Thea::Math::padPeriodic ( int i, int period )

Pad an integer to a multiple of a period.

Definition at line 164 of file Math.hpp.

 Matrix<4, 4, T> Thea::Math::perspectiveProjection ( T const & left, T const & right, T const & bottom, T const & top, T const & nearval, T const & farval, bool y_increases_upwards = `true` )

Constructs a 3D perspective projection matrix from the given parameters.

nearval and farval are the negative of the near and far plane Z values (to follow OpenGL conventions). Set y_increases_upwards to false if Y increases downwards instead, e.g. for screen pixel space.

Definition at line 587 of file MatrixUtil.hpp.

 double Thea::Math::pi ( )

The constant Pi.

Definition at line 292 of file Math.hpp.

Convert an angle from radians to degrees.

Definition at line 365 of file Math.hpp.

 Matrix<2, 2, T> Thea::Math::rotation ( T const & radians )

Matrix to rotate a 2D vector about the origin by an angle (in radians).

Definition at line 285 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationArc ( Vector< 3, T > const & start_dir, Vector< 3, T > const & end_dir, bool normalize_dirs = `true` )

Return the matrix corresponding to the rotation from one direction vector to another.

Parameters
 start_dir The vector to rotate from. end_dir The vector to rotate to. normalize_dirs If false, the directions will be assumed to have been pre-normalized to unit length before being passed to this function.

Definition at line 542 of file MatrixUtil.hpp.

 Quaternion Thea::Math::rotationArcQuat ( Vector< 3, T > const & start_dir, Vector< 3, T > const & end_dir, bool normalize_dirs = `true` )

Return the quaternion corresponding to the rotation from one direction vector to another.

Use this instead of Eigen's Quaternion::FromTwoVectors() when the input vectors are pre-normalized, since the latter function will always normalize the input vectors, wasting two sqrt's. However, for most other practical purposes the two functions should have the same behavior.

Parameters
 start_dir The vector to rotate from. end_dir The vector to rotate to. normalize_dirs If false, the directions will be assumed to have been pre-normalized to unit length before being passed to this function.

Definition at line 489 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationAxisAngle ( Vector< 3, T > const & axis, T const & radians )

Rotate around the given 3D axis (need not be a unit vector) by a given angle.

Definition at line 298 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationEulerAnglesXYZ ( T const & yaw_radians, T const & pitch_radians, T const & roll_radians )

Rotate about the Z axis by the roll angle, then the Y axis by the pitch angle, and finally the X axis by the yaw angle.

Definition at line 336 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationEulerAnglesXZY ( T const & yaw_radians, T const & pitch_radians, T const & roll_radians )

Rotate about the Y axis by the roll angle, then the Z axis by the pitch angle, and finally the X axis by the yaw angle.

Definition at line 360 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationEulerAnglesYXZ ( T const & yaw_radians, T const & pitch_radians, T const & roll_radians )

Rotate about the Z axis by the roll angle, then the X axis by the pitch angle, and finally the Y axis by the yaw angle.

Definition at line 384 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationEulerAnglesYZX ( T const & yaw_radians, T const & pitch_radians, T const & roll_radians )

Rotate about the X axis by the roll angle, then the Z axis by the pitch angle, and finally the Y axis by the yaw angle.

Definition at line 408 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationEulerAnglesZXY ( T const & yaw_radians, T const & pitch_radians, T const & roll_radians )

Rotate about the Y axis by the roll angle, then the X axis by the pitch angle, and finally the Z axis by the yaw angle.

Definition at line 432 of file MatrixUtil.hpp.

 Matrix<3, 3, T> Thea::Math::rotationEulerAnglesZYX ( T const & yaw_radians, T const & pitch_radians, T const & roll_radians )

Rotate about the X axis by the roll angle, then the Y axis by the pitch angle, and finally the Z axis by the yaw angle.

Definition at line 456 of file MatrixUtil.hpp.

 float Thea::Math::round ( float x )

Round a real number to the nearest integer using the lrintf() routine.

Definition at line 313 of file Math.hpp.

 double Thea::Math::round ( double x )

Round a real number to the nearest integer using the lrint() routine.

Definition at line 320 of file Math.hpp.

 Matrix Thea::Math::scaling ( Vector< N, T > const & s )

Matrix to scale a point by the corresponding scaling parameter along each dimension.

Parameters
 s The vector of scaling factors per dimension.

Definition at line 268 of file MatrixUtil.hpp.

 Matrix Thea::Math::scaling ( T const & s )

Matrix to uniformaly scale a point by a scaling factor s.

Definition at line 276 of file MatrixUtil.hpp.

 int Thea::Math::sign ( T const & x )

Get the sign of a number.

Returns
-1 if the number is strictly less than zero, 1 if the number is strictly greater than zero, 0 if the number is zero.

Definition at line 340 of file Math.hpp.

 int solveCubic ( double c0, double c1, double c2, double c3, double * roots )

Real roots of cubic equation c0 + c1 * x + c2 * x^2 + c3 * x^3 = 0.

Returns
The number of real roots found (0, 1, 2 or 3).

Definition at line 93 of file Math.cpp.

 int solveLinear ( double c0, double c1, double * root )

Root of linear equation c0 + c1 * x = 0.

Returns
The number of roots found (0 or 1).

Definition at line 51 of file Math.cpp.

 int solveQuadratic ( double c0, double c1, double c2, double * roots )

Distinct real roots x1, x2 of quadratic equation c0 + c1 * x + c2 * x^2 = 0.

Returns
The number of distinct real roots found (0, 1 or 2).

Definition at line 64 of file Math.cpp.

 int solveQuartic ( double c0, double c1, double c2, double c3, double c4, double * roots )

Real roots of quartic equation c0 + c1 * x + c2 * x^2 + c3 * x^3 + c4 * x^4 = 0.

Returns
The number of real roots found (0, 1, 2, 3 or 4).

Definition at line 166 of file Math.cpp.

 T Thea::Math::square ( T const & x )

Compute the square of a value.

Definition at line 97 of file Math.hpp.

 double Thea::Math::twoPi ( )

The constant 2 * Pi.

Definition at line 306 of file Math.hpp.

 SparseMatrixWrapper Thea::Math::wrapMatrix ( Eigen::SparseMatrixBase< MatrixT > & m )

Convenience function for creating a MatrixWrapper object from a matrix reference, without needing to specify template parameters.

Definition at line 122 of file SparseMatrixWrapper.hpp.

 SparseMatrixWrapper Thea::Math::wrapMatrix ( Eigen::SparseMatrixBase< MatrixT > * m )

Convenience function for creating a MatrixWrapper object from a matrix pointer, without needing to specify template parameters.

Definition at line 133 of file SparseMatrixWrapper.hpp.

 MatrixWrapper Thea::Math::wrapMatrix ( Eigen::MatrixBase< MatrixT > & m )

Convenience function for creating a MatrixWrapper object from a matrix reference, without needing to specify template parameters.

Definition at line 146 of file MatrixWrapper.hpp.

 MatrixWrapper Thea::Math::wrapMatrix ( Eigen::MatrixBase< MatrixT > * m )

Convenience function for creating a MatrixWrapper object from a matrix pointer, without needing to specify template parameters.

Definition at line 157 of file MatrixWrapper.hpp.