PGA2D
2D Euclidean Projective Geometric Algebra (PGA) library, where elements represent Lines (vectors) and Points (bivectors).
See bivector.net for more information.
This can be useful for solving common geometric problems in 2D space, such as finding the intersection, union, or distance between lines and points.
expect # Line <1x + 2y + 3 = 0> line1 = line { a: 1, b: 2, c: 3 } # Line <4x + 5y + 6 = 0> line2 = line { a: 4, b: 5, c: 6 } # The intersection of the two lines intersection = meet line1 line2 # equal to the Point <1,-2> eq (normalize intersection) (normalize (point { x: 1, y: -2 }))
Multivector
A multivector is a general element of the algebra R(2, 0, 1), i.e. 2D Projective Geometric Algebra (PGA).
It is basically an 8-element array of the basis elements of 2D PGA. For example, a multivector can be written as:
a + b*e0 + c*e1 + d*e2 + e*e01 + f*e20 + g*e12 + h*e012
Where the basis elements are;
s
Scalare0
Vectore1
Vectore2
Vectore01
Bivectore20
Bivectore12
Bivectore012
Trivector / Pseudoscalar
zero : Multivector
An empty multivector with all components zeroed to 0.0
origin : Multivector
In PGA, the origin is represented by the e12 bivector.
scalar : F32 -> Multivector
Scalar (grade-0 element)
line : { a : F32, b : F32, c : F32 } -> Multivector
Line (grade-1 element) with equation ax + by + c = 0
Represented as a*e1 + b*e2 + c*e0
point : { x : F32, y : F32 } -> Multivector
Euclidian Point (grade-2 element) with coordinates x,y
Represented as: x*e20 + y*e01 + e12
idealPoint : { x : F32, y : F32 } -> Multivector
Ideal Point (grade-2 element) with coordinates x,y
Represented as: x*e20 + y*e01
rotor : { angle : F32, cx : F32, cy : F32 } -> Multivector
A multivector that represents a rotor which performs a rotation
by angle
around the center point cx,cy
translator : { dx : F32, dy : F32 } -> Multivector
A multivector that represents a translator which performs a translation by dx,dy
meet : Multivector, Multivector -> Multivector
Meet (wedge, outer product)
Used for intersections, e.g. intersect two Lines to get a Point
join : Multivector, Multivector -> Multivector
Join (vee, regressive product)
Used for joins, e.g. join two Points to get a Line
dot : Multivector, Multivector -> Multivector
Dot (scalar / inner product)
Used for for projections, e.g. dot two Lines to get a scalar
mul : Multivector, Multivector -> Multivector
Multiply (geometric product)
Used for Reflections, Rotations, Translations
add : Multivector, Multivector -> Multivector
Add
e.g. add two Lines to get a Line
sub : Multivector, Multivector -> Multivector
Subtract
e.g. subtract two Lines to get a Line
smul : F32, Multivector -> Multivector
Scalar Multiplication
e.g. multiply a Line by a scalar
muls : Multivector, F32 -> Multivector
Scalar Multiplication
e.g. multiply a Line by a scalar
sadd : F32, Multivector -> Multivector
Scalar Addition
e.g. add a scalar to a Line
adds : Multivector, F32 -> Multivector
Scalar Addition
e.g. add a scalar to a Line
ssub : F32, Multivector -> Multivector
Scalar Subtraction
e.g. subtract a scalar from a Line
subs : Multivector, F32 -> Multivector
Scalar Subtraction
e.g. subtract a scalar from a Line
reverse : Multivector -> Multivector
Reverse Operator
Reverse the order of the basis blades
dual : Multivector -> Multivector
Dual (Not) Operator
Poincare duality operator
conjugate : Multivector -> Multivector
Conjugate Operator
involute : Multivector -> Multivector
Involute Operator
normalize : Multivector -> Multivector
Normalize
e.g. normalize a Line to have a magnitude of 1
eq : Multivector, Multivector -> Bool
Helper function for comparing Multivectors with tolerance
pi : F32
s : F32 -> Multivector
Scalar
e0 : F32 -> Multivector
Basis vector
e1 : F32 -> Multivector
Basis vector
e2 : F32 -> Multivector
Basis vector
e01 : F32 -> Multivector
Basis bivector
e20 : F32 -> Multivector
Basis bivector
e12 : F32 -> Multivector
Basis bivector
e012 : F32 -> Multivector
Basis pseudoscalar