Grassmann Algebra in Game Development. Eric Lengyel, PhD Terathon Software



Similar documents
Introduction to Geometric Algebra Lecture II

Section 1.1. Introduction to R n

Geometric Algebra Primer. Jaap Suter

Orthogonal Projections

Linear Algebra Notes for Marsden and Tromba Vector Calculus

α = u v. In other words, Orthogonal Projection

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

Notes on Orthogonal and Symmetric Matrices MENU, Winter 2013

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

x1 x 2 x 3 y 1 y 2 y 3 x 1 y 2 x 2 y 1 0.

Math 241, Exam 1 Information.

Recall that two vectors in are perpendicular or orthogonal provided that their dot

11.1. Objectives. Component Form of a Vector. Component Form of a Vector. Component Form of a Vector. Vectors and the Geometry of Space

1 Introduction to Matrices

Math 215 HW #6 Solutions

Data Mining: Algorithms and Applications Matrix Math Review

THREE DIMENSIONAL GEOMETRY

Lectures notes on orthogonal matrices (with exercises) Linear Algebra II - Spring 2004 by D. Klain

ISOMETRIES OF R n KEITH CONRAD

Similarity and Diagonalization. Similar Matrices

[1] Diagonal factorization

JUST THE MATHS UNIT NUMBER 8.5. VECTORS 5 (Vector equations of straight lines) A.J.Hobson

MATH 304 Linear Algebra Lecture 9: Subspaces of vector spaces (continued). Span. Spanning set.

L 2 : x = s + 1, y = s, z = 4s Suppose that C has coordinates (x, y, z). Then from the vector equality AC = BD, one has

A QUICK GUIDE TO THE FORMULAS OF MULTIVARIABLE CALCULUS

Mathematics Course 111: Algebra I Part IV: Vector Spaces

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

Inner product. Definition of inner product

Equations Involving Lines and Planes Standard equations for lines in space

Lecture L3 - Vectors, Matrices and Coordinate Transformations

Figure 1.1 Vector A and Vector F

Vectors Math 122 Calculus III D Joyce, Fall 2012

CS3220 Lecture Notes: QR factorization and orthogonal transformations

1 Sets and Set Notation.

Linear Algebra: Vectors

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

Solving Simultaneous Equations and Matrices

Section 5.3. Section 5.3. u m ] l jj. = l jj u j + + l mj u m. v j = [ u 1 u j. l mj

Mechanics 1: Vectors

1 Comparing Complex Numbers to Clifford Algebra

1.3. DOT PRODUCT If θ is the angle (between 0 and π) between two non-zero vectors u and v,

discuss how to describe points, lines and planes in 3 space.

Orthogonal Diagonalization of Symmetric Matrices

Recall the basic property of the transpose (for any A): v A t Aw = v w, v, w R n.

Math for Game Programmers: Dual Numbers. Gino van den Bergen

v 1 v 3 u v = (( 1)4 (3)2, [1(4) ( 2)2], 1(3) ( 2)( 1)) = ( 10, 8, 1) (d) u (v w) = (u w)v (u v)w (Relationship between dot and cross product)

Vector Algebra CHAPTER 13. Ü13.1. Basic Concepts

South Carolina College- and Career-Ready (SCCCR) Pre-Calculus

Rotation Matrices and Homogeneous Transformations

LINES AND PLANES CHRIS JOHNSON

3. INNER PRODUCT SPACES

1 VECTOR SPACES AND SUBSPACES

Orthogonal Projections and Orthonormal Bases

Chapter 17. Orthogonal Matrices and Symmetries of Space

is in plane V. However, it may be more convenient to introduce a plane coordinate system in V.

Linear Algebra Review. Vectors

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

A vector is a directed line segment used to represent a vector quantity.

LINEAR ALGEBRA. September 23, 2010

Unified Lecture # 4 Vectors

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

Section 13.5 Equations of Lines and Planes

18.06 Problem Set 4 Solution Due Wednesday, 11 March 2009 at 4 pm in Total: 175 points.

Computational Geometry Lab: FEM BASIS FUNCTIONS FOR A TETRAHEDRON

Vector Math Computer Graphics Scott D. Anderson

Problem Set 5 Due: In class Thursday, Oct. 18 Late papers will be accepted until 1:00 PM Friday.

9 Multiplication of Vectors: The Scalar or Dot Product

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

Numerical Analysis Lecture Notes

Introduction to General and Generalized Linear Models

13.4 THE CROSS PRODUCT

Chapter 4. Moment - the tendency of a force to rotate an object

Vector Spaces; the Space R n

Vector has a magnitude and a direction. Scalar has a magnitude

The Essentials of CAGD

NOTES ON LINEAR TRANSFORMATIONS

FURTHER VECTORS (MEI)

521493S Computer Graphics. Exercise 2 & course schedule change

Introduction to Matrix Algebra

Two vectors are equal if they have the same length and direction. They do not

Nonlinear Iterative Partial Least Squares Method

DERIVATIVES AS MATRICES; CHAIN RULE

Dot product and vector projections (Sect. 12.3) There are two main ways to introduce the dot product

MAT188H1S Lec0101 Burbulla

Section 9.5: Equations of Lines and Planes

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

CHAPTER FIVE. 5. Equations of Lines in R 3

12.5 Equations of Lines and Planes

( ) which must be a vector

The Matrix Elements of a 3 3 Orthogonal Matrix Revisited

Computing Orthonormal Sets in 2D, 3D, and 4D

Geometric description of the cross product of the vectors u and v. The cross product of two vectors is a vector! u x v is perpendicular to u and v

The Characteristic Polynomial

MAT 1341: REVIEW II SANGHOON BAEK

CONTROLLABILITY. Chapter Reachable Set and Controllability. Suppose we have a linear system described by the state equation

State of Stress at Point

Name: Section Registered In:

Manifold Learning Examples PCA, LLE and ISOMAP

Solutions to old Exam 1 problems

Transcription:

Grassmann Algebra in Game Development 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

Clifford Algebras In n dimensions, add n special units e 1,, e n to the real numbers Choose whether each e i squares to 0, 1, or 1

Complex numbers One unit e that squares to 1

Dual numbers One unit e that squares to 0

Geometric Algebra All n of the e i square to 1 For n = 3, quaternions included here

Dual Quaternions Part of 4D Clifford algebra with e 2 1 1 2 e 2 1 e 2 3 1 2 e 4 0

Grassmann Algebra All n of the e i square to 0

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: a b Read a wedge b

The wedge product Operates on scalars, vectors, and more Ordinary multiplication for scalars s and t: s t t s st s v v s sv The square of a vector v is always zero: v v0

Wedge product anticommutativity Zero square implies vectors anticommute a b a b 0 a a a b b a b b a b b a 0 0 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: e, e, e 1 2 3 Then a 3D vector a can be expressed as a e a e a e 1 1 2 2 3 3

Bivectors in 3D a a a b b b a b e e e e e e 1 1 2 2 3 3 1 1 2 2 3 3 a b a b e e a b e e a b e e 1 2 1 2 1 3 1 3 2 1 2 1 a b e e a b e e a b e e 2 3 2 3 3 1 3 1 3 2 3 2 a b a b a b e e a b a b e e 2 3 3 2 2 3 3 1 1 3 3 1 a b a b e e 1 2 2 1 1 2

Bivectors in 3D The result of the wedge product has three components on the basis e e, e e, e e 2 3 3 1 1 2 Written in order of which basis vector is missing from the basis bivector

Bivectors in 3D Do the components look familiar? a b a b a b e e a b a b e e 2 3 3 2 2 3 3 1 1 3 3 1 a b a b e e 1 2 2 1 1 2 These are identical to the components produced by the cross product a b

Shorthand notation e e e 12 1 2 e e e 23 2 3 e e e 31 3 1 e e e e 123 1 2 3

Bivectors in 3D a b a b a b e a b a b e 2 3 3 2 23 3 1 1 3 31 a b a b e 1 2 2 1 12

Comparison with cross product The cross product is not associative: abc abc The cross product is only defined in 3D The wedge product is associative, and it s defined in all dimensions

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: a b c a b c a b c a b c a b c a b c a b c 1 2 3 2 3 1 3 1 2 1 3 2 2 1 3 3 2 1 e e e 1 2 3 The magnitude is 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 a b c produces the same magnitude as but also extends to higher dimensions ab 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 2 n 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 e, e, e, e 1 2 3 4 Number of basis bivectors is 4 6 2 There are 4 basis trivectors

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: M 1 0 0 0 1 0 0 0 1

Cross product transform 1,0,0 0,1,0 0,0,1 M1,0,0 M0,1,0 1,0,0 0,1,0 0,0, 1 Not the same as M 0,0,1 0,0,1

Cross product transform

Cross product transform In general, for 3 x 3 matrix M, M a e a e a e a M a M a M MaMb 1 1 2 2 3 3 1 1 2 2 3 3 a M a M a M b M b M b M 1 1 2 2 3 3 1 1 2 2 3 3

Cross product transform MaMb a b a b M M 2 3 3 2 2 3 a b a b M M 3 1 1 3 3 1 a b a b M M 1 2 2 1 1 2

Products of matrix columns Other dot products are zero M M M det M 2 3 1 M M M det M 3 1 2 M M M det M 1 2 3

Matrix inversion Cross products as rows of matrix: M M det M 0 0 2 3 M M M 0 det M 0 3 1 M M 0 0 det M 1 2

Cross product transform Transforming the cross product requires the inverse matrix: M M 2 3 M M det MM 3 1 M M 1 2 1

Cross product transform Transpose the inverse to get right result: det M M T a b a b a b a b 2 3 3 2 a b 3 1 1 3 a b 1 2 2 1 a2b3 a3b2 M 2 M 3 a3b1 a1b3 M 3 M1 a b a b M M 1 2 2 1 1 2

Cross product transform Transformation formula: det Result of cross product must be transformed by inverse transpose times determinant T Ma Mb M M ab

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 really a bivector, and it 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 NT0 UN MT 0 T T T N U MT U M U M T 1 0

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 e 1...e n Each (n 1)-vector basis element uses all except one of the spatial directions e 1...e n

Symmetry in three dimensions Vector basis and bivector (n 1) basis e e e 1 2 3 e e e 2 3 e e 3 1 e 1 2

Symmetry in four dimensions Vector basis and trivector (n 1) basis e e e e 1 2 3 4 e e e 2 3 4 e e e 1 4 3 e e e 1 2 4 e e e 1 3 2

Dual basis Use special notation for wedge product of all but one basis vector: e e e e 1 2 3 4 e e e e 2 1 4 3 e e e e 3 1 2 4 e e e e 4 1 3 2

Dual basis Order of wedged basis vectors chosen so that eiei e1 e 2 e 3 e 4

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 a e a e a e b e b e b e 1 1 2 2 3 3 1 1 2 2 3 3 a b a b a b e e e 1 1 2 2 3 3 1 2 3 They complement each other, and fill in the volume element

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

Diffuse lighting N L is really the antiscalar given by N L N transforms with det MM T N L transforms as det M M T N ML T N det det M N L 1 M M ML

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: e e 1 2 We call it the antiwedge product

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 And A B A B has grade r + s has grade n (n r) (n s) = r + s n

Antiwedge product in 3D e e e e e e e 1 2 2 3 3 1 3 e e e e e e e 2 3 3 1 1 2 1 e e e e e e e 3 1 1 2 2 3 2

Similar shorthand notation e e e 12 1 2 e e e 23 2 3 e e e 31 3 1 e e e e 123 1 2 3

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: P x, y, z, w Conveniently allows affine transformation through 4 x 4 matrix Used throughout 3D graphics

Homogeneous points To project onto 3D space, find where 4D vector intersects subspace where w = 1 P x, y, z, w P 3D x y z,, w w w

Homogeneous points

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: e, e, e, e 1 2 3 4 e, e, e, e, e, e e, e, e, e 12 23 31 41 42 43 1 2 3 4 Antiscalar unit (quadvector)

Homogeneous lines Take wedge product of two 4D points P, P, P,1 P P P x y z x 1 y 2 z 3 4 P e e e e Q, Q, Q,1 Q Q Q x y z x 1 y 2 z 3 4 Q e e e e

Homogeneous lines Qx Px 41 Q y Py 42 Qz Pz 43 P Q P Q P Q P Q P Q P Q P Q e e e e e e y z z y 23 z x x z 31 x y y x 12 This bivector spans a 2D plane in 4D In subspace where w = 1, this is a 3D line

Homogeneous lines

Homogeneous lines The 4D bivector can be decomposed into two 3D components: A tangent vector and a moment bivector These are perpendicular Qx Px 41 Q y Py 42 Qz Pz 43 P Q P Q P Q P Q P Q P Q P Q e e e e e e y z z y 23 z x x z 31 x y y x 12

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 Tangent T vector is Moment M bivector is Q P 3D 3D P3D Q 3D Qx Px 41 Q y Py 42 Qz Pz 43 P Q P Q P Q P Q P Q P Q P Q e e e e e e y z z y 23 z x x z 31 x y y x 12

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 L Q P : PQ A bunch of seemingly arbitrary formulas in Plücker coordinates demystified

Homogeneous planes Take wedge product of three 4D points P, P, P,1 P P P x y z x 1 y 2 z 3 4 P e e e e Q, Q, Q,1 Q Q Q x y z x 1 y 2 z 3 4 Q e e e e R, R, R,1 R R R x y z x 1 y 2 z 3 4 R e e e e

Homogeneous planes P Q R N e N e N e De x 1 y 2 z 3 4 N is the 3D normal bivector D is the offset from origin in units of N N P Q Q R R P 3D 3D 3D 3D 3D 3D D P Q R 3D 3D 3D

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 4D Entity Vector (1-space) Bivector (2-space) Trivector (3-space) 3D Geometry Point (0-space) Line (1-space) Plane (2-space) We always project onto the 3D subspace where w = 1

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 L 1 have tangent T 1 and moment M 1 Let L 2 have tangent T 2 and moment M 2 Then, L L T M T M 1 2 1 2 2 1 L L T M T M 1 2 1 2 2 1

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 d L T L 1 2 T 1 2 (Here, numerator is 4D antiwedge product, and denominator is 3D wedge product.)

Weighting Points, lines, and planes have weights in homogeneous coordinates Entity Point Line Plane Weight w coordinate Tangent component T 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 Cross product axial vector Dot product Scalar triple product Plücker coordinates Operations in Plücker coordinates Transform normals with inverse transpose New school Wedge product bivector Antiwedge vector / antivector Triple wedge product 4D bivectors 4D wedge / antiwedge products Transform antivectors with adjugate transpose

Slides available online at http://www.terathon.com/lengyel/ Contact lengyel@terathon.com @EricLengyel At Terathon booth (#741) all week

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

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.

Explicit formulas Define points P, Q and planes E, F, and line L Px, Py, Pz,1 Px 1 Py 2 Pz 3 4 Qx, Qy, Qz,1 Qx 1 Qy 2 Qz 3 4 E x, E y, E z, Ew E x 1 E y 2 E z 3 Ew 4 Fx, Fy, Fz, Fw Fx 1 Fy 2 Fz 3 Fw 4 P e e e e Q e e e e E e e e e F e e e e L T e T e T e M e M e M e x 41 y 42 z 43 x 23 y 31 z 12

Explicit formulas Product of two points Qx Px 41 Q y Py 42 Qz Pz 43 P Q P Q P Q P Q P Q P Q P Q e e e e e e y z z y 23 z x x z 31 x y y x 12

Explicit formulas Product of two planes E zfy E yfz E xfz E zfx E yfx E xfy E F e e e 41 42 43 E F E F e E F E F e E F E F e x w w x 23 y w w y 31 z w w z 12

Explicit formulas Product of line and point TyPz TzPy M x 1 TzPx TxPz M y 2 TxPy TyPx M z e Px M x PyM y Pz M z L P e e 3 4 e

Explicit formulas Product of line and plane M ze y M ye z TxE w M xe z M ze x TyE w M ye x M xe y TzE w e3 E xtx E yty E ztz e4 L E e e 1 2