Giter Club home page Giter Club logo

terathon-math-library's Introduction

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:

  • Vector2D – A 2D vector (x, y) that extends to four dimensions as (x, y, 0, 0).
  • Vector3D – A 3D vector (x, y, z) that extends to four dimensions as (x, y, z, 0).
  • Vector4D – A 4D vector (x, y, z, w).
  • Point2D – A 2D point (x, y) that extends to four dimensions as (x, y, 0, 1).
  • Point3D – A 3D point (x, y, z) that extends to four dimensions as (x, y, z, 1).
  • Matrix2D – A 2×2 matrix.
  • Matrix3D – A 3×3 matrix.
  • Matrix4D – A 4×4 matrix.
  • Transform4D – A 4×4 matrix with fourth row always (0, 0, 0, 1).
  • Quaternion – A convention quaternion xi + yj + zk + w.
  • Bivector3D – A 3D bivector x e23 + y e31 + z e12.
  • Bivector4D – A 4D bivector (line) vx e41 + vy e42 + vz e43 + mx e23 + my e31 + mz e12.
  • Trivector4D – A 4D trivector (plane) x e234 + y e314 + z e124 + w e321.
  • Motor – A 4D motion operator rx e41 + ry e42 + rz e43 + rw 𝟙 + ux e23 + uy e31 + uz e12 + uw.

Component Swizzling

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

  • v.x – The x component of v.
  • v.xy – A 2D vector having the x and y components of v.
  • v.yzx – A 3D vector having the components of v in the order (y, z, x).

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:

  • m.m12 – The (1,2) entry of m.
  • m.row0 – The first row of m.
  • m.col1 – The second column of m.
  • m.matrix2D – The upper-left 2×2 submatrix of m.
  • m.transpose – The transpose of 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, points, lines, and planes. (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 useless 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.

terathon-math-library's People

Contributors

ericlengyel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.