Math module
Fixed-size vectors/colors, matrices, transforms, rays, orthonormal bases, and other mathy things.
Darts provides many commonly-used vector math data types, including n-dimensional vectors (Vec), rays (Ray), boxes (Box), and n x n matrices (Mat). Behind the scenes, darts uses the excellent linalg library for this.
Each of these structures is templated based on both the dimension and the underlying datatype. Darts defines typedefs for low dimensions and common datatypes. The pattern for the typedefs is: DataDimType
, where Data
is Vec
, Ray
, or Box
, and Type
is a single-character shorthand for the underlying datatype:
f
: for 32-bit single-precisionfloat
d
: for a 64-bitdouble
-precision floating point numberi
: for an integer,int32_t
u
: for an unsigned integer,uint32_t
c
: for a char,uint8_t
For instance, a vector of three 32-bit floating point values has a typedef Vec3f
, and a 2D box of integer values would be Box2i
.
RGB and RGBA colors can be represented by Color3 and Color4, which are just aliases for Vec3
and Vec4
. There are typedefs for Color3Type
and Color4Type
.
For the matrix (Mat) the pattern is MatDimDimType
. For instance, Mat33f
for a 3x3 matrix of floats, or Mat44d
for a 4x4 matrix of doubles.
Darts also provides two data type specifically designed for working in 3D: a 3D orthonormal basis class (#ONB), and linear 3D transformation (Transform) represented using a 4x4 matrix.
Classes
Functions
-
template<typename T>auto coordinate_system(const Vec3<T>& z) -> std::pair<Vec3<T>, Vec3<T>>
- Construct an orthonormal coordinate system given one vector
a
.
Basic darts vector/matrix/color types
-
template<int N, class T>using Vec = la::vec<T, N>
- Generic
N
dimensional vector. -
template<class T, int M, int N>using Mat = la::mat<T, M, N>
- Generic
M
xN
matrix. -
template<int N, class T>using Color = la::vec<T, N>
- Generic
N
dimensional color. -
template<class T>using Color3 = Color<3, T>
- RGB color of type T.
-
template<class T>using Color4 = Color<4, T>
- RGBA color of type T.
Interpolation utilities
-
template<typename T>auto mod(T a, T b) -> T
- Always-positive modulo operation.
Color utilities
Working with colors
- auto to_sRGB(const Color3f& c) -> Color3f
- Convert from linear RGB to sRGB.
- auto to_linear_RGB(const Color3f& c) -> Color3f
- Convert from sRGB to linear RGB.
- auto luminance(const Color3f& c) -> float
- Return the associated luminance.
- auto viridis(float t) -> Color3f
- Evaluate the Matplotlib viridis colormap.
- auto inferno(float t) -> Color3f
- Evaluate the Matplotlib inferno colormap.
- auto magma(float t) -> Color3f
- Evaluate the Matplotlib magma colormap.
- auto plasma(float t) -> Color3f
- Evaluate the Matplotlib plasma colormap.
Math constants
A few useful constants
- #define M_PI
- #define INV_PI
- #define INV_TWOPI
- #define INV_FOURPI
- #define SQRT_TWO
- #define INV_SQRT_TWO
Typedef documentation
#include <darts/math.h>
template<int N, class T>
using Vec = la::vec<T, N>
Generic N
dimensional vector.
#include <darts/math.h>
template<class T, int M, int N>
using Mat = la::mat<T, M, N>
Generic M
x N
matrix.
#include <darts/math.h>
template<int N, class T>
using Color = la::vec<T, N>
Generic N
dimensional color.
#include <darts/math.h>
template<class T>
using Color3 = Color<3, T>
RGB color of type T.
#include <darts/math.h>
template<class T>
using Color4 = Color<4, T>
RGBA color of type T.
Function documentation
#include <darts/math.h>
template<typename T>
std::pair<Vec3<T>, Vec3<T>> coordinate_system(const Vec3<T>& z)
Construct an orthonormal coordinate system given one vector a
.
Parameters | |
---|---|
z in | The coordinate system's local z axis direction. |
Returns | The local x and y-axes orthogonal to z. |
#include <darts/math.h>
template<typename T>
T mod(T a,
T b)
Always-positive modulo operation.
Color3f to_sRGB(const Color3f& c)
#include <darts/math.h>
Convert from linear RGB to sRGB.
Color3f to_linear_RGB(const Color3f& c)
#include <darts/math.h>
Convert from sRGB to linear RGB.
float luminance(const Color3f& c)
#include <darts/math.h>
Return the associated luminance.
Color3f viridis(float t)
#include <darts/math.h>
Evaluate the Matplotlib viridis colormap.
Color3f inferno(float t)
#include <darts/math.h>
Evaluate the Matplotlib inferno colormap.
Color3f magma(float t)
#include <darts/math.h>
Evaluate the Matplotlib magma colormap.
Color3f plasma(float t)
#include <darts/math.h>
Evaluate the Matplotlib plasma colormap.