fundamentals of grassmann algebra · fundamentals of grassmann algebra eric lengyel, phd terathon...
TRANSCRIPT
Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software
Math used in 3D programming
● Dot / cross products, scalar triple product
● Planes as 4D vectors
● Homogeneous coordinates
● Plücker coordinates for 3D lines
● Transforming normal vectors and planes with the inverse transpose of a matrix
Math used in 3D programming
● These concepts often used without a complete understanding of the big picture
● Can be used in a way that is not natural
● Different pieces used separately without knowledge of the connection among them
There is a bigger picture
● All of these arise as part of a single mathematical system
● Understanding the big picture provides deep insights into seemingly unusual properties
● Knowledge of the relationships among these concepts makes better 3D programmers
History
● Hamilton, 1843
● Discovered quaternion product
● Applied to 3D rotations
● Not part of Grassmann algebra
History
● Grassmann, 1844
● Formulated progressive and regressive products
● Understood geometric meaning
● Published “Algebra of Extension”
History
● Clifford, 1878
● Unified Hamilton’s and Grassmann’s work
● Basis for modern geometric algebra and various algebras used in physics
History
Outline
● Grassmann algebra in 3-4 dimensions
● Wedge product, bivectors, trivectors...
● Transformations
● Homogeneous model
● Geometric computation
● Programming considerations
The wedge product
● Also known as:
● The progressive product
● The exterior product
● Gets name from symbol:
● Read “a wedge b”
a b
The wedge product
● Operates on scalars, vectors, and more
● Ordinary multiplication for scalars s and t:
● The square of a vector v is always zero:
0 v v
s s s v v v
s t t s st
Wedge product anticommutativity
● Zero square implies vectors anticommute
0
0
0
a b a b
a a a b b a b b
a b b a
a b b a
Bivectors
● Wedge product between two vectors produces a “bivector”
● A new mathematical entity
● Distinct from a scalar or vector
● Represents an oriented 2D area
● Whereas a vector represents an oriented 1D direction
● Scalars are zero-dimensional values
Bivectors
● Bivector is two directions and magnitude
Bivectors
● Order of multiplication matters
a b b a
Bivectors in 3D
● Start with 3 orthonormal basis vectors:
● Then a 3D vector a can be expressed as
1 2 3, ,e e e
1 1 2 2 3 3a a a e e e
Bivectors in 3D
1 1 2 2 3 3 1 1 2 2 3 3a a a b b b a b e e e e e e
1 2 1 2 1 3 1 3 2 1 2 1
2 3 2 3 3 1 3 1 3 2 3 2
a b a b a b
a b a b a b
a b e e e e e e
e e e e e e
2 3 3 2 2 3 3 1 1 3 3 1
1 2 2 1 1 2
a b a b a b a b
a b a b
a b e e e e
e e
Bivectors in 3D
● The result of the wedge product has three components on the basis
● Written in order of which basis vector is missing from the basis bivector
2 3 3 1 1 2, , e e e e e e
Bivectors in 3D
● Do the components look familiar?
● These are identical to the components produced by the cross product a × b
2 3 3 2 2 3 3 1 1 3 3 1
1 2 2 1 1 2
a b a b a b a b
a b a b
a b e e e e
e e
Shorthand notation
12 1 2
23 2 3
31 3 1
123 1 2 3
e e e
e e e
e e e
e e e e
Bivectors in 3D
2 3 3 2 23 3 1 1 3 31
1 2 2 1 12
a b a b a b a b
a b a b
a b e e
e
Comparison with cross product
● The cross product is not associative:
● The cross product is only defined in 3D
● The wedge product is associative, and it’s defined in all dimensions
a b c a b c
Trivectors
● Wedge product among three vectors produces a “trivector”
● Another new mathematical entity
● Distinct from scalars, vectors, and bivectors
● Represents a 3D oriented volume
Trivectors
a b c
Trivectors in 3D
● A 3D trivector has one component:
● The magnitude is
1 2 3 2 3 1 3 1 2 1 3 2 2 1 3 3 2 1
1 2 3
a b c a b c a b c a b c a b c a b c
a b c
e e e
det a b c
Trivectors in 3D
● 3D trivector also called pseudoscalar or antiscalar
● Only one component, so looks like a scalar
● Flips sign under reflection
Scalar Triple Product
● The product
produces the same magnitude as
but also extends to higher dimensions
a b c
a b c
Grading
● The grade of an entity is the number of vectors wedged together to make it
● Scalars have grade 0
● Vectors have grade 1
● Bivectors have grade 2
● Trivectors have grade 3
● Etc.
3D multivector algebra
● 1 scalar element
● 3 vector elements
● 3 bivector elements
● 1 trivector element
● No higher-grade elements
● Total of 8 multivector basis elements
Multivectors in general dimension
● In n dimensions, the number of basis k-vector elements is
● This produces a nice symmetry
● Total number of basis elements always 2n
n
k
Multivectors in general dimension
Dimension Graded elements
1 1 1
2 1 2 1
3 1 3 3 1
4 1 4 6 4 1
5 1 5 10 10 5 1
Four dimensions
● Four basis vectors
● Number of basis bivectors is
● There are 4 basis trivectors
1 2 3 4, , ,e e e e
46
2
Vector / bivector confusion
● In 3D, vectors have three components
● In 3D, bivectors have three components
● Thus, vectors and bivectors look like the same thing!
● This is a big reason why knowledge of the difference is not widespread
Cross product peculiarities
● Physicists noticed a long time ago that the cross product produces a different kind of vector
● They call it an “axial vector”, “pseudovector”, “covector”, or “covariant vector”
● It transforms differently than ordinary “polar vectors” or “contravariant vectors”
Cross product transform
● Simplest example is a reflection:
1 0 0
0 1 0
0 0 1
M
Cross product transform
● Not the same as
1,0,0 0,1,0 0,0,1
1,0,0 0,1,0
1,0,0 0,1,0 0,0, 1
M M
0,0,1 0,0,1M
Cross product transform
Cross product transform
● In general, for 3 x 3 matrix M,
1 1 2 2 3 3 1 1 2 2 3 3a a a a a a M e e e M M M
1 1 2 2 3 3 1 1 2 2 3 3a a a b b b
Ma Mb
M M M M M M
Cross product transform
2 3 3 2 2 3
3 1 1 3 3 1
1 2 2 1 1 2
a b a b
a b a b
a b a b
Ma Mb
M M
M M
M M
Products of matrix columns
● Other dot products are zero
2 3 1
3 1 2
1 2 3
det
det
det
M M M M
M M M M
M M M M
Matrix inversion
● Cross products as rows of matrix:
2 3
3 1
1 2
det 0 0
0 det 0
0 0 det
M M M
M M M M
M M M
Cross product transform
● Transforming the cross product requires the inverse matrix:
2 3
13 1
1 2
det
M M
M M M M
M M
Cross product transform
● Transpose the inverse to get right result:
2 3 3 2
3 1 1 3
1 2 2 1
2 3 3 2 2 3 3 1 1 3 3 1
1 2 2 1 1 2
det T
a b a b
a b a b
a b a b
a b a b a b a b
a b a b
M M
M M M M
M M
Cross product transform
● Transformation formula:
● Result of cross product must be transformed by inverse transpose times determinant
det T Ma Mb M M a b
Cross product transform
● If M is orthogonal, then inverse transpose is the same as M
● If the determinant is positive, then it can be left out if you don’t care about length
● Determinant times inverse transpose is called adjugate transpose
Cross product transform
● What’s really going on here?
● When we take a cross product, we are really creating a bivector
● Bivectors are not vectors, and they don’t behave like vectors
Normal “vectors”
● A triangle normal is created by taking the cross product between two tangent vectors
● A normal is a bivector and transforms as such
Normal “vector” transformation
Classical derivation
● Standard proof for inverse transpose for transforming normals:
● Preserve zero dot product with tangent
● Misses extra factor of det M
1
0
0
0T T
T
T
N T
UN MT
N U MT
U M
U M
Matrix inverses
● In general, the i-th row of the inverse of M is 1/det M times the wedge product of all columns of M except column i.
Higher dimensions
● In n dimensions, the (n−1)-vectors have n components, just as 1-vectors do
● Each 1-vector basis element uses exactly one of the spatial directions e1...en
● Each (n−1)-vector basis element uses all except one of the spatial directions e1...en
Symmetry in three dimensions
● Vector basis and bivector (n−1) basis
1
2
3
e
e
e
2 3
3 1
1 2
e e
e e
e e
Symmetry in four dimensions
● Vector basis and trivector (n−1) basis
2 3 4
1 4 3
1 2 4
1 3 2
e e e
e e e
e e e
e e e
1
2
3
4
e
e
e
e
Dual basis
● Use special notation for wedge product of all but one basis vector:
1 2 3 4
2 1 4 3
3 1 2 4
4 1 3 2
e e e e
e e e e
e e e e
e e e e
Dual basis
● Instead of saying (n−1)-vector, we call these “antivectors”
● In n dimensions, antivector always means a quantity expressed on the basis with grade n−1
Vector / antivector product
● Wedge product between vector and antivector is the origin of the dot product
● They complement each other, and “fill in” the volume element
1 1 2 2 3 3 1 1 2 2 3 3
1 1 2 2 3 3 1 2 3
a a a b b b
a b a b a b
e e e e e e
e e e
Vector / antivector product
● Many of the dot products you take are actually vector / antivector wedge products
● For instance, N • L in diffuse lighting
● N is an antivector
● Calculating volume of extruded bivector
Diffuse Lighting
The regressive product
● Grassmann realized there is another product symmetric to the wedge product
● Not well-known at all
● Most books on geometric algebra leave it out completely
● Very important product, though!
The regressive product
● Operates on antivectors in a manner symmetric to how the wedge product operates on vectors
● Uses an upside-down wedge:
● We call it the “antiwedge” product
1 2e e
The antiwedge product
● Has same properties as wedge product, but for antivectors
● Operates in complementary space on dual basis or “antibasis”
The antiwedge product
● Whereas the wedge product increases grade, the antiwedge product decreases it
● Suppose, in n-dimensional Grassmann algebra, A has grade r and B has grade s
● Then has grade r + s
● And has grade
n − (n − r) − (n − s) = r + s − n
A B
A B
Antiwedge product in 3D
1 2 2 3 3 1 3
2 3 3 1 1 2 1
3 1 1 2 2 3 2
e e e e e e e
e e e e e e e
e e e e e e e
Similar shorthand notation
12 1 2
23 2 3
31 3 1
123 1 2 3
e e e
e e e
e e e
e e e e
Join and meet
● Wedge product joins vectors together
● Analogous to union
● Antiwedge product joins antivectors
● Antivectors represent absence of geometry
● Joining antivectors is like removing vectors
● Analogous to intersection
● Called a meet operation
Homogeneous coordinates
● Points have a 4D representation:
● Conveniently allows affine transformation through 4 x 4 matrix
● Used throughout 3D graphics
, , ,x y z wP
Homogeneous points
● To project onto 3D space, find where 4D vector intersects subspace where w = 1
3D
, , ,
, ,
x y z w
x y z
w w w
P
P
Homogeneous model
● With Grassmann algebra, homogeneous model can be extended to include 3D points, lines, and planes
● Wedge and antiwedge products naturally perform union and intersection operations among all of these
4D Grassmann Algebra
● Scalar unit
● Four vectors:
● Six bivectors:
● Four antivectors:
● Antiscalar unit (quadvector)
1 2 3 4, , ,e e e e
12 23 31 41 42 43, , , , ,e e e e e e
1 2 3 4, , ,e e e e
Homogeneous lines
● Take wedge product of two 4D points
1 2 3 4, , ,1x y z x y zP P P P P P P e e e e
1 2 3 4, , ,1x y z x y zQ Q Q Q Q Q Q e e e e
Homogeneous lines
● This bivector spans a 2D plane in 4D
● In subspace where w = 1, this is a 3D line
41 42 43
23 31 12
x x y y z z
y z z y z x x z x y y x
Q P Q P Q P
P Q P Q P Q P Q P Q P Q
P Q e e e
e e e
Homogeneous lines
● The 4D bivector no longer contains any information about the two points used to create it
● Contrary to parametric origin / direction representation
Homogeneous lines
● The 4D bivector can be decomposed into two 3D components:
● A tangent vector and a moment bivector
● These are perpendicular
41 42 43
23 31 12
x x y y z z
y z z y z x x z x y y x
Q P Q P Q P
P Q P Q P Q P Q P Q P Q
P Q e e e
e e e
Homogeneous lines
● Tangent T vector is
● Moment M bivector is
3D 3DQ P
3D 3DP Q
41 42 43
23 31 12
x x y y z z
y z z y z x x z x y y x
Q P Q P Q P
P Q P Q P Q P Q P Q P Q
P Q e e e
e e e
Moment bivector
Plücker coordinates
● Origin of Plücker coordinates revealed!
● They are the coefficients of a 4D bivector
● A line L in Plücker coordinates is
● A bunch of seemingly arbitrary formulas in Plücker coordinates will become clear
: L Q P P Q
Homogeneous planes
● Take wedge product of three 4D points
1 2 3 4, , ,1x y z x y zP P P P P P P e e e e
1 2 3 4, , ,1x y z x y zQ Q Q Q Q Q Q e e e e
1 2 3 4, , ,1x y z x y zR R R R R R R e e e e
Homogeneous planes
● N is the 3D normal bivector
● D is the offset from origin in units of N
1 2 3 4x y zN N N D P Q R e e e e
3D 3D 3D 3D 3D 3D
3D 3D 3DD
N P Q Q R R P
P Q R
Plane transformation
● A homogeneous plane is a 4D antivector
● It transforms by the inverse of a 4 x 4 matrix
● Just like a 3D antivector transforms by the inverse of a 3 x 3 matrix
● Orthogonality not common here due to translation in the matrix
Projective geometry
● We always project onto the 3D subspace where w = 1
4D Entity 3D Geometry
Vector (1-space) Point (0-space)
Bivector (2-space) Line (1-space)
Trivector (3-space) Plane (2-space)
Geometric computation in 4D
● Wedge product
● Multiply two points to get the line containing both points
● Multiply three points to get the plane containing all three points
● Multiply a line and a point to get the plane containing the line and the point
Geometric computation in 4D
● Antiwedge product
● Multiply two planes to get the line where they intersect
● Multiply three planes to get the point common to all three planes
● Multiply a line and a plane to get the point where the line intersects the plane
Geometric computation in 4D
● Wedge or antiwedge product
● Multiply a point and a plane to get the signed minimum distance between them in units of the normal magnitude
● Multiply two lines to get a special signed crossing value
Product of two lines
● Wedge product gives an antiscalar (quadvector or 4D volume element)
● Antiwedge product gives a scalar
● Both have same sign and magnitude
● Grassmann treated scalars and antiscalars as the same thing
Product of two lines
● Let L1 have tangent T1 and moment M1
● Let L2 have tangent T2 and moment M2
● Then,
1 2 1 2 2 1 L L T M T M
1 2 1 2 2 1 L L T M T M
Product of two lines
● The product of two lines gives a “crossing” relation
● Positive value means clockwise crossing
● Negative value means counterclockwise
● Zero if lines intersect
Crossing relation
Distance between lines
● Product of two lines also relates to signed minimum distance between them
● (Here, numerator is 4D antiwedge product, and denominator is 3D wedge product.)
1 2
1 2
d
L L
T T
Ray-triangle intersection
● Application of line-line product
● Classic barycentric calculation difficult due to floating-point round-off error
● Along edge between two triangles, ray can miss both or hit both
● Typical solution involves use of ugly epsilons
Ray-triangle intersection
● Calculate 4D bivectors for triangle edges and ray
● Take antiwedge products between ray and three edges
● Same sign for all three edges is a hit
● Impossible to hit or miss both triangles sharing edge
● Need to handle zero in consistent way
Weighting
● Points, lines, and planes have “weights” in homogeneous coordinates
Entity Weight
Point w coordinate
Line Tangent component T
Plane x, y, z component
Weighting
● Mathematically, the weight components can be found by taking the antiwedge product with the antivector (0,0,0,1)
● We would never really do that, though, because we can just look at the right coefficients
Normalized lines
● Tangent component has unit length
● Magnitude of moment component is perpendicular distance to the origin
Normalized planes
● (x,y,z) component has unit length
● Wedge product with (normalized) point is perpendicular distance to plane
Programming considerations
● Convenient to create classes to represent entities of each grade
● Vector4D
● Bivector4D
● Antivector4D
Programming considerations
● Fortunate happenstance that C++ has an overloadable operator ^ that looks like a wedge
● But be careful with operator precedence if you overload ^ to perform wedge product
● Has lowest operator precedence, so get used to enclosing wedge products in parentheses
Combining wedge and antiwedge
● The same operator can be used for wedge product and antiwedge product
● Either they both produce the same scalar and antiscalar magnitudes with the same sign
● Or one of the products is identically zero
● For example, you would always want the antiwedge product for two planes because the wedge product is zero for all inputs
Summary
Old school New school
Cross product axial vector Wedge product bivector
Dot product Antiwedge vector / antivector
Scalar triple product Triple wedge product
Plücker coordinates 4D bivectors
Operations in Plücker coordinates 4D wedge / antiwedge products
Transform normals with inverse transpose
Transform antivectors with adjugate transpose
Supplemental Slides
Example application
● Calculation of shadow region planes from light position and frustum edges
● Simply a wedge product
Points of closest approach
● Wedge product of line tangents gives complement of direction between closest points
Points of closest approach
● Plane containing this direction and first line also contains closest point on second line
Two dimensions
● 1 scalar unit
● 2 basis vectors
● 1 bivector / antiscalar unit
● No cross product
● All rotations occur in plane of 1 bivector
One dimension
● 1 scalar unit
● 1 single-component basis vector
● Also antiscalar unit
● Equivalent to “dual numbers”
● All numbers have form a + be
● Where e2 = 0
Explicit formulas
● Define points P, Q and planes E, F, and line L
1 2 3 4, , ,1x y z x y zP P P P P P P e e e e
1 2 3 4, , ,1x y z x y zQ Q Q Q Q Q Q e e e e
1 2 3 4, , ,x y z w x y z wE E E E E E E E E e e e e
1 2 3 4, , ,x y z w x y z wF F F F F F F F F e e e e
41 42 43 23 31 12x y z x y zT T T M M M L e e e e e e
Explicit formulas
● Product of two points
41 42 43
23 31 12
x x y y z z
y z z y z x x z x y y x
Q P Q P Q P
P Q P Q P Q P Q P Q P Q
P Q e e e
e e e
Explicit formulas
● Product of two planes
41 42 43
23 31 12
z y y z x z z x y x x y
x w w x y w w y z w w z
E F E F E F E F E F E F
E F E F E F E F E F E F
E F e e e
e e e
Explicit formulas
● Product of line and point
1 2
3 4
y z z y x z x x z y
x y y x z x x y y z z
T P T P M T P T P M
T P T P M P M P M P M
L P e e
e e
Explicit formulas
● Product of line and plane
1 2
3 4
z y y z x w x z z x y w
y x x y z w x x y y z z
M E M E T E M E M E T E
M E M E T E E T E T E T
L E e e
e e