Geometric Algebra

In this section, we describe a simple implementation of the \(G_{3,0,0}\) algebra. Little disclaimer, this implementation is quite simple and is not really meant for high-performance contexts nor low-memory efficiency. It is inspired by the generated library provided by Bivector.net but enforcing a strict right-hand convention to remain consistent with the linear algebra implemented in this header.

We refer the reader to other geometric algebra libraries/generators/implementations such as :

Implementation

This module lives inside the hk::maths::vga namespace and provide a unique data structure mvec3f representing a multivector in this algebraic structure.

struct mvec3f
{
    union
    {
        float at[8];
        struct {float s, x,y,z, xy, yz, zx, xyz;};
    };

    // [...]
};

Here is an example of creating a vector using algebra:

vga::mvec3f x  = vga::mvec3f::basis_x();
vga::mvec3f y  = vga::mvec3f::basis_y();
vga::mvec3f z  = vga::mvec3f::basis_z();

vga::mvec3f v = 2.f * x + 0.5f * y + 1.5f * z;

This data structure comes with some operators:

  • * or product function: performing the geometric product between multivectors

  • ^ or wedge or outer: performing the outer/wedge product between multivectors

  • dot or inner: performing the inner/dot product between multivectors

This implementation also provides

  • v.grade_0 : \( \langle A \rangle_0 \) the scalar part of the multivector \(A\)

  • v.grade_1 : \( \langle A \rangle_1 \) the vector part of the multivector \(A\)

  • v.grade_2 : \( \langle A \rangle_2 \) the bivector/pseudovector part of the multivector \(A\)

  • v.grade_3 : \( \langle A \rangle_3 \) the trivector/pseudoscalar part of the multivector \(A\)

  • reverse : denoted \(A^\dagger\) reversing blades from the multivector

  • norm_sqr : denoted \( |A|^2 = \langle A^\dagger A \rangle_0 \)

  • norm : denoted \( |A| = \sqrt{ \langle A^\dagger A \rangle_0 } \)

  • inverse : denoted \(A^\star = A^\dagger / |A|^2 \) the inverse of \(A\), meaning \(AA^\star = 1\)

duality is achieved using the pseudoscalar \(A I^{-1}\) with \(I^{-1} = (e_{123})^{-1}\)

vga::mvec3f I_inv = inverse(vga::mvec3f::basis_xyz());
vga::mvec3f A = ...

vga::mvec3f A_dual = A * I_inv;

Algebraic structure

Basis vectors and blades:

\(e\)

\(e_1\)

\(e_2\)

\(e_3\)

\(e_{12}\)

\(e_{23}\)

\(e_{31}\)

\(e_{123}\)

\(1\)

\(\mathbf{x}\)

\(\mathbf{y}\)

\(\mathbf{z}\)

\(\mathbf{xy}\)

\(\mathbf{yz}\)

\(\mathbf{zx}\)

\(\mathbf{xyz}\)

Square table:

\(e^2\)

\(e_1^2\)

\(e_2^2\)

\(e_3^2\)

\(e_{12}^2\)

\(e_{23}^2\)

\(e_{31}^2\)

\(e_{123}^2\)

\(1^2\)

\(\mathbf{x}^2\)

\(\mathbf{y}^2\)

\(\mathbf{z}^2\)

\((\mathbf{xy})^2\)

\((\mathbf{yz})^2\)

\((\mathbf{zx})^2\)

\((\mathbf{xyz})^2\)

\(1\)

\(1\)

\(1\)

\(1\)

\(-1\)

\(-1\)

\(-1\)

\(-1\)

Cayley tables

Wedge product:

\(\wedge\)

\(1\)

\(\mathbf{x}\)

\(\mathbf{y}\)

\(\mathbf{z}\)

\(\mathbf{xy}\)

\(\mathbf{yz}\)

\(\mathbf{zx}\)

\(\mathbf{xyz}\)

\(1\)

\(1\)

\(\mathbf{x}\)

\(\mathbf{y}\)

\(\mathbf{z}\)

\(\mathbf{xy}\)

\(\mathbf{yz}\)

\(\mathbf{zx}\)

\(\mathbf{xyz}\)

\(\mathbf{x}\)

\(\mathbf{x}\)

\(0\)

\(\mathbf{xy}\)

\(-\mathbf{zx}\)

\(0\)

\(\mathbf{xyz}\)

\(0\)

\(0\)

\(\mathbf{y}\)

\(\mathbf{y}\)

\(-\mathbf{xy}\)

\(0\)

\(\mathbf{yz}\)

\(0\)

\(0\)

\(\mathbf{xyz}\)

\(0\)

\(\mathbf{z}\)

\(\mathbf{z}\)

\(\mathbf{zx}\)

\(-\mathbf{yz}\)

\(0\)

\(\mathbf{xyz}\)

\(0\)

\(0\)

\(0\)

\(\mathbf{xy}\)

\(\mathbf{xy}\)

\(0\)

\(0\)

\(\mathbf{xyz}\)

\(0\)

\(0\)

\(0\)

\(0\)

\(\mathbf{yz}\)

\(\mathbf{yz}\)

\(\mathbf{xyz}\)

\(0\)

\(0\)

\(0\)

\(0\)

\(0\)

\(0\)

\(\mathbf{zx}\)

\(\mathbf{zx}\)

\(0\)

\(\mathbf{xyz}\)

\(0\)

\(0\)

\(0\)

\(0\)

\(0\)

\(\mathbf{xyz}\)

\(\mathbf{xyz}\)

\(0\)

\(0\)

\(0\)

\(0\)

\(0\)

\(0\)

\(0\)

Dot product:

\(\cdot\)

\(1\)

\(\mathbf{x}\)

\(\mathbf{y}\)

\(\mathbf{z}\)

\(\mathbf{xy}\)

\(\mathbf{yz}\)

\(\mathbf{zx}\)

\(\mathbf{xyz}\)

\(1\)

\(1\)

\(\mathbf{x}\)

\(\mathbf{y}\)

\(\mathbf{z}\)

\(\mathbf{xy}\)

\(\mathbf{yz}\)

\(\mathbf{zx}\)

\(\mathbf{xyz}\)

\(\mathbf{x}\)

\(\mathbf{x}\)

\(1\)

\(0\)

\(0\)

\(\mathbf{y}\)

\(0\)

\(-\mathbf{z}\)

\(\mathbf{yz}\)

\(\mathbf{y}\)

\(\mathbf{y}\)

\(0\)

\(1\)

\(0\)

\(-\mathbf{x}\)

\(\mathbf{z}\)

\(0\)

\(\mathbf{zx}\)

\(\mathbf{z}\)

\(\mathbf{z}\)

\(0\)

\(0\)

\(1\)

\(0\)

\(-\mathbf{y}\)

\(\mathbf{x}\)

\(\mathbf{xy}\)

\(\mathbf{xy}\)

\(\mathbf{xy}\)

\(-\mathbf{y}\)

\(\mathbf{x}\)

\(0\)

\(-1\)

\(0\)

\(0\)

\(-\mathbf{z}\)

\(\mathbf{yz}\)

\(\mathbf{yz}\)

\(0\)

\(-\mathbf{z}\)

\(\mathbf{y}\)

\(0\)

\(-1\)

\(0\)

\(-\mathbf{x}\)

\(\mathbf{zx}\)

\(\mathbf{zx}\)

\(\mathbf{z}\)

\(0\)

\(-\mathbf{x}\)

\(0\)

\(0\)

\(-1\)

\(-\mathbf{y}\)

\(\mathbf{xyz}\)

\(\mathbf{xyz}\)

\(\mathbf{yz}\)

\(\mathbf{zx}\)

\(\mathbf{xy}\)

\(-\mathbf{z}\)

\(-\mathbf{x}\)

\(-\mathbf{y}\)

\(-1\)