Home

Awesome

Terathon Math Library

This is a C++ math library containing classes for vectors, matrices, quaternions, and elements of projective geometric algebra. The specific classes are the following:

2D rigid geometric algebra

3D rigid geometric algebra

2D conformal geometric algebra

3D conformal geometric algebra

Component Swizzling

Vector components can be swizzled using shading-language syntax. As an example, the following expressions are all valid for a Vector3D object v:

Support for repeated components in a swizzle can be enabled by defining TERATHON_SWIZZLE_REPEAT. This is disabled by default because the large number of additional swizzling possibilities increases compile times substantially. Swizzles with repeated components are always const so that it's not possible to assign to them.

Rows, columns, and submatrices can be extracted from matrix objects using a similar syntax. As an example, the following expressions are all valid for a Matrix3D object m:

All of the above are generally free operations, with no copying, when their results are consumed by an expression. For more information, see Eric Lengyel's 2018 GDC talk Linear Algebra Upgraded.

Geometric Algebra

The ^ operator is overloaded for cases in which the wedge or antiwedge product can be applied between vectors, bivectors, flat points, lines, planes, round points, dipoles, circles, and spheres. (Note that ^ has lower precedence than just about everything else, so parentheses will be necessary.)

The library does not provide operators that directly calculate the geometric product and antiproduct because they would tend to generate inefficient code and produce intermediate results having unnecessary types when something like the sandwich product Qp ⟇ ~Q appears in an expression. Instead, there are Transform() functions that take some object p for the first parameter and the motor Q with which to transform it for the second parameter.

See Eric Lengyel's Projective Geometric Algebra website for more information about operations among these types.

API Documentation

There is API documentation embedded in the header files. The formatted equivalent can be found in the C4 Engine documentation.

Licensing

Separate proprietary licenses are available from Terathon Software. Please send an email with details about your particular use case if you are interested.