Carna  Version 3.3.2
Classes | Typedefs | Functions
Carna::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 \( ) \). More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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, rows > 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\).
 
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, rows > 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.
 
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.

Function Documentation

◆ basis4f() [1/2]

Matrix4f Carna::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 242 of file math.h.

◆ basis4f() [2/2]

Matrix4f Carna::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 259 of file math.h.

◆ clamp()

template<typename T >
T Carna::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 64 of file math.h.

◆ computeFastGradient3f()

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

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

Since
API Version 3.3.0

Definition at line 580 of file math.h.

◆ frustum4f() [1/2]

Matrix4f Carna::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 516 of file math.h.

◆ frustum4f() [2/2]

Matrix4f Carna::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 547 of file math.h.

◆ orthogonal3f()

Vector3f Carna::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 367 of file math.h.

◆ plane4f()

Matrix4f Carna::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 471 of file math.h.

◆ rotation4f()

template<typename Vector >
Matrix4f Carna::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 348 of file math.h.

◆ scaling4f() [1/2]

template<typename VectorElementType >
Matrix4f Carna::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 305 of file math.h.

◆ scaling4f() [2/2]

Matrix4f Carna::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 312 of file math.h.

◆ translation4f()

template<typename Vector >
Matrix4f Carna::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 284 of file math.h.