fundamentals of grassmann algebra · fundamentals of grassmann algebra eric lengyel, phd terathon...

110
Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software

Upload: voque

Post on 23-May-2018

236 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software

Page 2: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 3: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 4: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 5: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

History

● Hamilton, 1843

● Discovered quaternion product

● Applied to 3D rotations

● Not part of Grassmann algebra

Page 6: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

History

● Grassmann, 1844

● Formulated progressive and regressive products

● Understood geometric meaning

● Published “Algebra of Extension”

Page 7: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

History

● Clifford, 1878

● Unified Hamilton’s and Grassmann’s work

● Basis for modern geometric algebra and various algebras used in physics

Page 8: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

History

Page 9: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Outline

● Grassmann algebra in 3-4 dimensions

● Wedge product, bivectors, trivectors...

● Transformations

● Homogeneous model

● Geometric computation

● Programming considerations

Page 10: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

The wedge product

● Also known as:

● The progressive product

● The exterior product

● Gets name from symbol:

● Read “a wedge b”

a b

Page 11: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 12: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 13: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 14: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Bivectors

● Bivector is two directions and magnitude

Page 15: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Bivectors

● Order of multiplication matters

a b b a

Page 16: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 17: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 18: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 19: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 20: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 21: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 22: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 23: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Trivectors

● Wedge product among three vectors produces a “trivector”

● Another new mathematical entity

● Distinct from scalars, vectors, and bivectors

● Represents a 3D oriented volume

Page 24: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Trivectors

a b c

Page 25: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 26: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Trivectors in 3D

● 3D trivector also called pseudoscalar or antiscalar

● Only one component, so looks like a scalar

● Flips sign under reflection

Page 27: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Scalar Triple Product

● The product

produces the same magnitude as

but also extends to higher dimensions

a b c

a b c

Page 28: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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.

Page 29: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 30: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 31: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 32: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 33: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 34: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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”

Page 35: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Cross product transform

● Simplest example is a reflection:

1 0 0

0 1 0

0 0 1

M

Page 36: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 37: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Cross product transform

Page 38: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 39: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 40: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 41: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 42: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 43: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 44: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 45: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 46: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 47: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 48: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Normal “vector” transformation

Page 49: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 50: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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.

Page 51: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 52: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 53: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 54: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 55: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 56: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 57: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 58: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Diffuse Lighting

Page 59: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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!

Page 60: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 61: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

The antiwedge product

● Has same properties as wedge product, but for antivectors

● Operates in complementary space on dual basis or “antibasis”

Page 62: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 63: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 64: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 65: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 66: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Homogeneous coordinates

● Points have a 4D representation:

● Conveniently allows affine transformation through 4 x 4 matrix

● Used throughout 3D graphics

, , ,x y z wP

Page 67: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 68: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 69: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 70: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 71: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 72: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Homogeneous lines

● The 4D bivector no longer contains any information about the two points used to create it

● Contrary to parametric origin / direction representation

Page 73: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 74: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 75: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Moment bivector

Page 76: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 77: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 78: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 79: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 80: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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)

Page 81: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 82: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 83: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 84: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 85: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 86: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 87: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Crossing relation

Page 88: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 89: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 90: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 91: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Weighting

● Points, lines, and planes have “weights” in homogeneous coordinates

Entity Weight

Point w coordinate

Line Tangent component T

Plane x, y, z component

Page 92: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 93: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Normalized lines

● Tangent component has unit length

● Magnitude of moment component is perpendicular distance to the origin

Page 94: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Normalized planes

● (x,y,z) component has unit length

● Wedge product with (normalized) point is perpendicular distance to plane

Page 95: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Programming considerations

● Convenient to create classes to represent entities of each grade

● Vector4D

● Bivector4D

● Antivector4D

Page 96: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 97: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 98: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 99: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

● Slides available online at

● http://www.terathon.com/lengyel/

● Contact

[email protected]

Page 100: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Supplemental Slides

Page 101: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Example application

● Calculation of shadow region planes from light position and frustum edges

● Simply a wedge product

Page 102: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Points of closest approach

● Wedge product of line tangents gives complement of direction between closest points

Page 103: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Points of closest approach

● Plane containing this direction and first line also contains closest point on second line

Page 104: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

Two dimensions

● 1 scalar unit

● 2 basis vectors

● 1 bivector / antiscalar unit

● No cross product

● All rotations occur in plane of 1 bivector

Page 105: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 106: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 107: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 108: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 109: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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

Page 110: Fundamentals of Grassmann Algebra · Fundamentals of Grassmann Algebra Eric Lengyel, PhD Terathon Software . Math used in 3D programming ... insights into seemingly unusual properties

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