LibCarna Version 3.4.0
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
LibCarna::base::math Namespace Reference

Provides set of math-related classes and functions. More...

Classes

struct  element_type_of
 Retrieves element types of vectors and scalars. General case assumes a scalar type. More...
 
struct  element_type_of< Eigen::Matrix< VectorElementType, rows, cols > >
 Retrieves element types of vectors and scalars. This is the specialization for vector and matrix types. More...
 
class  Ray
 Defines ray in \(D^d\) where \(D\) is the Scalar type derived from VectorType and \(d\) is dimension of VectorType. More...
 
class  Ray3f
 Defines ray in \(\mathbb R^3\). More...
 
class  RayPlaneHitTest
 Tests whether particular plane is hit by a Ray object. More...
 
class  RaySphereHitTest
 Tests whether sphere in origin is hit by a Ray object. More...
 
class  Span
 Defines an interval \(\left[a, b\right]\) with \(a,b \in\) T. More...
 
struct  Statistics
 Holds mean and variance of an characteristic. More...
 
class  VectorField
 Abstract definition of an \(\mathbb Z_0^3 \to T\) vector field where \(T\) is ValueType. More...
 

Typedefs

typedef Eigen::Matrix< float, 4, 4, Eigen::ColMajor > Matrix4f
 Defines \(\mathbb R^{4 \times 4}\) matrix.
 
typedef Eigen::Matrix< float, 3, 3, Eigen::ColMajor > Matrix3f
 Defines \(\mathbb R^{3 \times 3}\) matrix.
 
typedef Eigen::Matrix< float, 4, 1 > Vector4f
 Defines \(\mathbb R^{4 \times 1}\) vector.
 
typedef Eigen::Matrix< float, 3, 1 > Vector3f
 Defines \(\mathbb R^{3 \times 1}\) vector.
 
typedef Eigen::Matrix< float, 2, 1 > Vector2f
 Defines \(\mathbb R^{2 \times 1}\) vector.
 
typedef Eigen::Matrix< signed int, 3, 1 > Vector3i
 Defines \(\mathbb Z^{3 \times 1}\) vector.
 
typedef Eigen::Matrix< unsigned int, 3, 1 > Vector3ui
 Defines \(\mathbb Z^{3 \times 1}_{\geq 0}\) vector.
 
typedef Eigen::Matrix< unsigned int, 2, 1 > Vector2ui
 Defines \(\mathbb Z^{2 \times 1}_{\geq 0}\) vector.
 

Functions

template<typename T >
clamp (T val, T my_min, T my_max)
 Returns \( \min( \max( \) val \(, \) my_min \( ), \) my_max \( ) \).
 
template<typename T >
sq (T x)
 Computes and returns \( x^2 \).
 
float deg2rad (float deg)
 Converts degrees to radians.
 
float rad2deg (float rad)
 Converts radians to degrees.
 
template<typename T >
epsilon ()
 Defines the maximum difference of two objects treated as equal.
 
template<>
float epsilon< float > ()
 Defines the maximum difference of two single-precision floating point objects treated as equal.
 
template<>
double epsilon< double > ()
 Defines the maximum difference of two double-precision floating point objects treated as equal.
 
template<typename T >
length2 (const T &x)
 Retrieves the squared length of vector and scalar types. General case assumes scalar type.
 
template<typename VectorElementType , int dimension>
VectorElementType length2 (const Eigen::Matrix< VectorElementType, dimension, 1 > &x)
 Retrieves the squared length of vector and scalar types. This is the specialization for vector types.
 
template<typename InputType >
bool isEqual (const InputType &x, const InputType &y)
 Tells whether two objects are equal respectively to epsilon.
 
template<>
bool isEqual (const bool &x, const bool &y)
 Tells whether two objects are equal. This is the specialization for bool types.
 
Matrix4f identity4f ()
 Returns \(\mathbb R^{4 \times 4}\) identity matrix.
 
Matrix3f identity3f ()
 Returns \(\mathbb R^{3 \times 3}\) identity matrix.
 
template<typename MatrixType >
MatrixType zeros ()
 Returns matrix with zeros in all components.
 
Matrix4f basis4f (const Vector4f &x, const Vector4f &y, const Vector4f &z, const Vector4f &t=Vector4f(0, 0, 0, 0))
 Creates \(\mathbb R^{3 \times 3}\) basis embedded into a \(\mathbb R^{4 \times 4}\) homogenous coordinates matrix.
 
Matrix4f basis4f (const Vector3f &x, const Vector3f &y, const Vector3f &z, const Vector3f &t=Vector3f(0, 0, 0))
 
Matrix4f translation4f (float x, float y, float z)
 Returns matrix that translates homogeneous coordinates.
 
template<typename Vector >
Matrix4f translation4f (const Vector &v)
 
Matrix4f scaling4f (float x, float y, float z)
 Creates scaling matrix for homogeneous coordinates.
 
template<typename VectorElementType >
Matrix4f scaling4f (const Eigen::Matrix< VectorElementType, 3, 1 > &v)
 
Matrix4f scaling4f (float uniformScaleFactor)
 
Matrix4f rotation4f (float x, float y, float z, float radians)
 Creates rotation matrix for homogeneous coordinates. The rotation is performed around the axis that is specified by the vector with the components x, y and z.
 
template<typename Vector >
Matrix4f rotation4f (const Vector &v, float radians)
 
Matrix3f rotation3f (float x, float y, float z, float radians)
 Creates rotation matrix for homogeneous coordinates, but returns only the upper left \(3 \times 3\) sub-matrix.
 
Vector3f orthogonal3f (const Vector3f &in)
 Constructs \(\mathbb R^3\) vector that is orthogonal to in. The result is undefined if the squared length of in equals zero.
 
template<typename VectorElementType , int rows, typename WType >
Eigen::Matrix< VectorElementType, 4, 1 > vector4 (const Eigen::Matrix< VectorElementType, rows, 1 > &v, WType w)
 Creates 4-dimensional vector from 3-dimensional (or higher) with same component type, and a scalar that is appended as the fourth component.
 
template<typename VectorElementType , int rows>
Eigen::Matrix< VectorElementType, 3, 1 > vector3 (const Eigen::Matrix< VectorElementType, rows, 1 > &v)
 Creates 3-dimensional vector from 4-dimensional (or higher) with same component type by dropping the fourth component.
 
Matrix4f plane4f (const Vector3f &normal, float distance)
 Creates matrix that transforms from the tangent space of a plane with particular normal vector and origin distance to the space that normal and distance are given within.
 
Matrix4f plane4f (const Vector3f &normal, const Vector3f &support)
 
float translationDistance2 (const Matrix4f &m)
 Returns the squared length of the translation component of the homogeneous coordinates transformation matrix m.
 
template<typename Matrix >
Matrix::Scalar maxAbsElement (const Matrix &m)
 Returns \(\max_{i,j} \left|m_{i,j}\right|\) where $m$ is m.
 
Matrix4f frustum4f (float left, float right, float bottom, float top, float zNear, float zFar)
 Returns the projection matrix that is described by the specified frustum.
 
Matrix4f frustum4f (float fovRadiansHorizontal, float heightOverWidth, float zNear, float zFar)
 
Matrix4f ortho4f (float left, float right, float bottom, float top, float zNear, float zFar)
 Returns the projection matrix that is described by the specified box.
 
template<typename Sampler >
base::math::Vector3f computeFastGradient3f (Sampler func)
 Computes fast approximation of the gradient at the origin of the scalar field func.
 
template<typename ScalarType >
unsigned int round_ui (ScalarType x)
 Rounds x to the closest \(x' \in \mathbb Z_{\geq 0}\). Either the data type of \(x\) must be unsigned or \(x \geq 0\).
 
template<typename MatrixElementType , int cols, int rows>
Eigen::Matrix< unsigned int, cols, rowsround_ui (const Eigen::Matrix< MatrixElementType, cols, rows > &m)
 Rounds matrix m to such \(m'\) that every element in \(m'\) is close-most to its corresponding element in \(m\). Either the element data type of \(m\) must be unsigned or \(m_{i,j} \geq 0 \forall i,j\).
 
template<typename ScalarType >
ScalarType makeEven (ScalarType x, int s)
 Returns \(x\) if \(x\) is even and \(x + s\) if \(x\) is odd, where \(s \in \left\{-1, +1\right\}\). The data type of \(x\) must be integral.
 
template<typename MatrixElementType , int cols, int rows>
Eigen::Matrix< MatrixElementType, cols, rowsmakeEven (const Eigen::Matrix< MatrixElementType, cols, rows > &m, int s)
 Returns matrix \(m'\) of the same size like \(m\) where \(m'_{i,j} = m_{i,j}\) if \(m_{i,j}\) is even and \(m'_{i,j} = m_{i,j} + s\) if \(m_{i,j}\) is odd, where \(s \in \left\{-1, +1\right\}\). The element data type of \(m\) must be integral.
 
template<typename ResultType , typename SupportType >
ResultType mix (const SupportType &a, const SupportType &b, float t)
 Interpolates between and by t \(\in\left[0, 1\right]\) linearly.
 

Detailed Description

Provides set of math-related classes and functions.

Typedef Documentation

◆ Matrix3f

typedef Eigen::Matrix< float, 3, 3, Eigen::ColMajor > LibCarna::base::math::Matrix3f

Defines \(\mathbb R^{3 \times 3}\) matrix.

Definition at line 198 of file math.hpp.

◆ Matrix4f

typedef Eigen::Matrix< float, 4, 4, Eigen::ColMajor > LibCarna::base::math::Matrix4f

Defines \(\mathbb R^{4 \times 4}\) matrix.

Definition at line 197 of file math.hpp.

◆ Vector2f

Defines \(\mathbb R^{2 \times 1}\) vector.

Definition at line 201 of file math.hpp.

◆ Vector2ui

Defines \(\mathbb Z^{2 \times 1}_{\geq 0}\) vector.

Definition at line 204 of file math.hpp.

◆ Vector3f

Defines \(\mathbb R^{3 \times 1}\) vector.

Definition at line 200 of file math.hpp.

◆ Vector3i

Defines \(\mathbb Z^{3 \times 1}\) vector.

Definition at line 202 of file math.hpp.

◆ Vector3ui

Defines \(\mathbb Z^{3 \times 1}_{\geq 0}\) vector.

Definition at line 203 of file math.hpp.

◆ Vector4f

Defines \(\mathbb R^{4 \times 1}\) vector.

Definition at line 199 of file math.hpp.

Function Documentation

◆ basis4f() [1/2]

Matrix4f LibCarna::base::math::basis4f ( const Vector3f x,
const Vector3f y,
const Vector3f z,
const Vector3f t = Vector3f( 0, 0, 0 ) 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 263 of file math.hpp.

◆ basis4f() [2/2]

Matrix4f LibCarna::base::math::basis4f ( const Vector4f x,
const Vector4f y,
const Vector4f z,
const Vector4f t = Vector4f( 0, 0, 0, 0 ) 
)
inline

Creates \(\mathbb R^{3 \times 3}\) basis embedded into a \(\mathbb R^{4 \times 4}\) homogenous coordinates matrix.

Parameters
xthe x basis vector
ythe y basis vector
zthe z basis vector
tthe translation component

Definition at line 246 of file math.hpp.

◆ clamp()

template<typename T >
T LibCarna::base::math::clamp ( val,
my_min,
my_max 
)

Returns \( \min( \max( \) val \(, \) my_min \( ), \) my_max \( ) \).

Returns \( \left\{ \begin{array}{ll} \mathrm{max} & \mbox{if $\mathrm{val} > \mathrm{max}$} \\ \mathrm{min} & \mbox{if $\mathrm{val} < \mathrm{min}$} \\ \mathrm{val} & \mbox{else}.\end{array} \right. \)

Definition at line 68 of file math.hpp.

◆ computeFastGradient3f()

template<typename Sampler >
base::math::Vector3f LibCarna::base::math::computeFastGradient3f ( Sampler  func)

Computes fast approximation of the gradient at the origin of the scalar field func.

Definition at line 581 of file math.hpp.

◆ deg2rad()

float LibCarna::base::math::deg2rad ( float  deg)
inline

Converts degrees to radians.

Definition at line 85 of file math.hpp.

◆ epsilon()

template<typename T >
T LibCarna::base::math::epsilon ( )

Defines the maximum difference of two objects treated as equal.

Definition at line 102 of file math.hpp.

◆ epsilon< double >()

template<>
double LibCarna::base::math::epsilon< double > ( )
inline

Defines the maximum difference of two double-precision floating point objects treated as equal.

Definition at line 122 of file math.hpp.

◆ epsilon< float >()

template<>
float LibCarna::base::math::epsilon< float > ( )
inline

Defines the maximum difference of two single-precision floating point objects treated as equal.

Definition at line 112 of file math.hpp.

◆ frustum4f() [1/2]

Matrix4f LibCarna::base::math::frustum4f ( float  fovRadiansHorizontal,
float  heightOverWidth,
float  zNear,
float  zFar 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
fovRadiansHorizontalSpecifies the angle between the left and the right frustum planes.
heightOverWidthSpecifies the ratio \(\frac{\text{height}}{\text{width}}\) for the projection plane.
zNearSpecifies the distance of the projection plane to the eye.
zFarSpecifies the distance of the far clipping plane to the eye.

Definition at line 551 of file math.hpp.

◆ frustum4f() [2/2]

Matrix4f LibCarna::base::math::frustum4f ( float  left,
float  right,
float  bottom,
float  top,
float  zNear,
float  zFar 
)
inline

Returns the projection matrix that is described by the specified frustum.

The frustum consists of six clipping planes. The near clipping plane is also the plane that the 3D scene is projected upon. The planes are specified as follows:

  • left and right specify the horizontal coordinates where the left and right frustum planes intersect the near clipping plane.
  • top and bottom specify the vertical coordinates where the top and bottom frustum planes intersect the near clipping plane.
  • zNear and zFar specify the distance of the near and the far frustum planes to the eye.

Definition at line 520 of file math.hpp.

◆ identity3f()

Matrix3f LibCarna::base::math::identity3f ( )
inline

Returns \(\mathbb R^{3 \times 3}\) identity matrix.

Definition at line 219 of file math.hpp.

◆ identity4f()

Matrix4f LibCarna::base::math::identity4f ( )
inline

Returns \(\mathbb R^{4 \times 4}\) identity matrix.

Definition at line 209 of file math.hpp.

◆ isEqual() [1/2]

template<>
bool LibCarna::base::math::isEqual ( const bool x,
const bool y 
)
inline

Tells whether two objects are equal. This is the specialization for bool types.

Definition at line 192 of file math.hpp.

◆ isEqual() [2/2]

template<typename InputType >
bool LibCarna::base::math::isEqual ( const InputType x,
const InputType y 
)

Tells whether two objects are equal respectively to epsilon.

Definition at line 178 of file math.hpp.

◆ length2() [1/2]

template<typename VectorElementType , int dimension>
VectorElementType LibCarna::base::math::length2 ( const Eigen::Matrix< VectorElementType, dimension, 1 > &  x)

Retrieves the squared length of vector and scalar types. This is the specialization for vector types.

Definition at line 169 of file math.hpp.

◆ length2() [2/2]

template<typename T >
T LibCarna::base::math::length2 ( const T &  x)

Retrieves the squared length of vector and scalar types. General case assumes scalar type.

Definition at line 159 of file math.hpp.

◆ makeEven() [1/2]

template<typename MatrixElementType , int cols, int rows>
Eigen::Matrix< MatrixElementType, cols, rows > LibCarna::base::math::makeEven ( const Eigen::Matrix< MatrixElementType, cols, rows > &  m,
int  s 
)

Returns matrix \(m'\) of the same size like \(m\) where \(m'_{i,j} = m_{i,j}\) if \(m_{i,j}\) is even and \(m'_{i,j} = m_{i,j} + s\) if \(m_{i,j}\) is odd, where \(s \in \left\{-1, +1\right\}\). The element data type of \(m\) must be integral.

Definition at line 638 of file math.hpp.

◆ makeEven() [2/2]

template<typename ScalarType >
ScalarType LibCarna::base::math::makeEven ( ScalarType  x,
int  s 
)

Returns \(x\) if \(x\) is even and \(x + s\) if \(x\) is odd, where \(s \in \left\{-1, +1\right\}\). The data type of \(x\) must be integral.

Definition at line 625 of file math.hpp.

◆ maxAbsElement()

template<typename Matrix >
Matrix::Scalar LibCarna::base::math::maxAbsElement ( const Matrix m)

Returns \(\max_{i,j} \left|m_{i,j}\right|\) where $m$ is m.

Definition at line 495 of file math.hpp.

◆ mix()

ResultType LibCarna::base::math::mix ( const SupportType a,
const SupportType b,
float  t 
)

Interpolates between and by t \(\in\left[0, 1\right]\) linearly.

Definition at line 719 of file math.hpp.

◆ ortho4f()

Matrix4f LibCarna::base::math::ortho4f ( float  left,
float  right,
float  bottom,
float  top,
float  zNear,
float  zFar 
)
inline

Returns the projection matrix that is described by the specified box.

Definition at line 561 of file math.hpp.

◆ orthogonal3f()

Vector3f LibCarna::base::math::orthogonal3f ( const Vector3f in)
inline

Constructs \(\mathbb R^3\) vector that is orthogonal to in. The result is undefined if the squared length of in equals zero.

Obviously the vector was too short. Check this. If it was not, than something went wrong.

Definition at line 371 of file math.hpp.

◆ plane4f() [1/2]

Matrix4f LibCarna::base::math::plane4f ( const Vector3f normal,
const Vector3f support 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 475 of file math.hpp.

◆ plane4f() [2/2]

Matrix4f LibCarna::base::math::plane4f ( const Vector3f normal,
float  distance 
)
inline

Creates matrix that transforms from the tangent space of a plane with particular normal vector and origin distance to the space that normal and distance are given within.

Definition at line 460 of file math.hpp.

◆ rad2deg()

float LibCarna::base::math::rad2deg ( float  rad)
inline

Converts radians to degrees.

Definition at line 93 of file math.hpp.

◆ rotation3f()

Matrix3f LibCarna::base::math::rotation3f ( float  x,
float  y,
float  z,
float  radians 
)
inline

Creates rotation matrix for homogeneous coordinates, but returns only the upper left \(3 \times 3\) sub-matrix.

Definition at line 361 of file math.hpp.

◆ rotation4f() [1/2]

template<typename Vector >
Matrix4f LibCarna::base::math::rotation4f ( const Vector &  v,
float  radians 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 352 of file math.hpp.

◆ rotation4f() [2/2]

Matrix4f LibCarna::base::math::rotation4f ( float  x,
float  y,
float  z,
float  radians 
)
inline

Creates rotation matrix for homogeneous coordinates. The rotation is performed around the axis that is specified by the vector with the components x, y and z.

Definition at line 326 of file math.hpp.

◆ round_ui() [1/2]

template<typename MatrixElementType , int cols, int rows>
Eigen::Matrix< unsigned int, cols, rows > LibCarna::base::math::round_ui ( const Eigen::Matrix< MatrixElementType, cols, rows > &  m)

Rounds matrix m to such \(m'\) that every element in \(m'\) is close-most to its corresponding element in \(m\). Either the element data type of \(m\) must be unsigned or \(m_{i,j} \geq 0 \forall i,j\).

Definition at line 609 of file math.hpp.

◆ round_ui() [2/2]

template<typename ScalarType >
unsigned int LibCarna::base::math::round_ui ( ScalarType  x)

Rounds x to the closest \(x' \in \mathbb Z_{\geq 0}\). Either the data type of \(x\) must be unsigned or \(x \geq 0\).

Definition at line 598 of file math.hpp.

◆ scaling4f() [1/3]

Matrix4f LibCarna::base::math::scaling4f ( const Eigen::Matrix< VectorElementType, 3, 1 > &  v)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 309 of file math.hpp.

◆ scaling4f() [2/3]

Matrix4f LibCarna::base::math::scaling4f ( float  uniformScaleFactor)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 316 of file math.hpp.

◆ scaling4f() [3/3]

Matrix4f LibCarna::base::math::scaling4f ( float  x,
float  y,
float  z 
)
inline

Creates scaling matrix for homogeneous coordinates.

Definition at line 296 of file math.hpp.

◆ sq()

template<typename T >
T LibCarna::base::math::sq ( x)

Computes and returns \( x^2 \).

Definition at line 77 of file math.hpp.

◆ translation4f() [1/2]

template<typename Vector >
Matrix4f LibCarna::base::math::translation4f ( const Vector &  v)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 288 of file math.hpp.

◆ translation4f() [2/2]

Matrix4f LibCarna::base::math::translation4f ( float  x,
float  y,
float  z 
)
inline

Returns matrix that translates homogeneous coordinates.

Definition at line 275 of file math.hpp.

◆ translationDistance2()

float LibCarna::base::math::translationDistance2 ( const Matrix4f m)
inline

Returns the squared length of the translation component of the homogeneous coordinates transformation matrix m.

Definition at line 486 of file math.hpp.

◆ vector3()

template<typename VectorElementType , int rows>
Eigen::Matrix< VectorElementType, 3, 1 > LibCarna::base::math::vector3 ( const Eigen::Matrix< VectorElementType, rows, 1 > &  v)

Creates 3-dimensional vector from 4-dimensional (or higher) with same component type by dropping the fourth component.

Definition at line 449 of file math.hpp.

◆ vector4()

Eigen::Matrix< VectorElementType, 4, 1 > LibCarna::base::math::vector4 ( const Eigen::Matrix< VectorElementType, rows, 1 > &  v,
WType  w 
)

Creates 4-dimensional vector from 3-dimensional (or higher) with same component type, and a scalar that is appended as the fourth component.

Definition at line 438 of file math.hpp.

◆ zeros()

template<typename MatrixType >
MatrixType LibCarna::base::math::zeros ( )

Returns matrix with zeros in all components.

Definition at line 230 of file math.hpp.