Sie sind auf Seite 1von 73

-553

CS-553 Interactive Computer Graphics





Lecture 2:
Linear Algebra for CG

G. Papagiannakis

Interactive Computer Graphics, Spring 2013, University of Crete




Overview

a

Basic

linear algebra
concepts used in CG

Vectors

and Matrices

Basic

geometrical
concepts

u

au

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 2


LA Applications in AR

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 3


What we should know about Linear Algebra



3D

Coordinate geometry

Vectors
Dot

in 2 space and 3 space


product and cross product definitions and uses


Vector

and Matrix notation and algebra


Properties
Matrix

(matrix associativity but NOT matrix commutativity)


transpose and inverse definition, use and calculation


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 4


History of algebras.

Pamplona, V.F. 2006. Geometric Algebra brief introduction. 123, http://vitorpamplona.com/


wiki/Curriculum

Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 5


Vector and Matrix notation: a non-geometric


example I

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 6


Vector and Matrix notation: a non-geometric


example II

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 7


Vector and Matrix notation: a non-geometric


example III

What

do I pay?

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 8


Vector and Matrix notation: a non-geometric


example IV

Using

Matrix notation:

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 9


Cartesian
coordinate space

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 10


Vectors & vector space I


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 11


Vectors & vector space II


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 12


Vector addition

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 13


Adding vectors
visually

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 14


Scalar
Multiplication I

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 15


Scalar
Multiplication II:
Linear
Dependence

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 16


Basis vectors
of the plane

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 17


Euclidean space

A

vector n in the n-dimensional Euclidean space


n

v0
v1
...
...
...
vn 1

with vi

, i 0, ... n

is denoted:

vector can also be represented as row vector



Most CG books and APIs use column-major form

Addition and multiplication by scalar:

u

u0
u1
...
...
...
un1

v0
v1
...
...
...
vn1

u0 v0
u1 v1
...
...
...
un1 vn1

av

au0
au1
...
...
...
aun 1

nmeans addition and multiplication yield vectors of the same

space

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 18


Coordinate Systems

Right

handed coordinate system


x
z
Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 19


Vector Arithmetic Summary


[
b = [b

a = ax

ay

by

[
a b = [a
a = [ a
sa = [sa

]
b]
az
z

]
b ]

a + b = a x + bx

a y + by

a z + bz

bx

a y by

az

x
x

ay
say

az
saz

Interactive Computer Graphics, Spring 2013, University of Crete


]
Lecture 2: Linear Algebra in CG Slide 20

Vector Magnitude

The

magnitude (length) of a vector is:



2
x

2
y

v = v +v +v

2
z

vector with length=1.0 is called a unit vector



We can also normalize a vector to make it a unit vector:

v
v
Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 21


Dot Product

a b = ai bi
a b = a x bx + a y by + a z bz
a b = a b cos

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 22


Dot Product

a b = ai bi
a b = a x bx + a y by + a z bz
a b = a b cos
T

ab = a b

a b = ax

Interactive Computer Graphics, Spring 2013, University of Crete


ay

bx

a z by
bz

Lecture 2: Linear Algebra in CG Slide 23


Example: Angle Between Vectors



How

do you find the angle between vectors a and b?


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 24


Example: Angle Between Vectors



a b = a b cos
a b

cos =

a
b

b
1

= cos

a
b

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 25


Dot Products with General Vectors



The

dot product is a scalar value that tells us something about the


relationship between two vectors

If

ab > 0 then < 90


If

ab < 0 then > 90


If

ab = 0 then = 90 (or one or more of the vectors is degenerate


(0,0,0))

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 26


Dot Products with One Unit Vector



If

|u|=1.0 then au is the length of the projection of a onto

u

au

Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 27


Example: Distance to Plane



A

plane is described by a point p on the plane and a unit


normal n. Find the distance from point x to the plane

x

n

p


Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 28


Example: Distance to Plane



The

distance is the length of the projection of x-p onto n:


dist = (x p) n

x

n

x-p

p


Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 29


Dot Products with Unit Vectors



0 < ab <
ab = 0
1

ab = 1

b

a

-1 < ab < 0

ab = -1

Interactive Computer Graphics, Spring 2013, University of Crete

ab

a = b = 1.0
a b = cos( )
Lecture 2: Linear Algebra in CG Slide 30

Cross Product

i
a b = ax
bx

j
ay
by

k
az
bz

a b = a y bz a z by

a z bx a x bz

Interactive Computer Graphics, Spring 2013, University of Crete


a x by a y bx

Lecture 2: Linear Algebra in CG Slide 31


Properties of the Cross Product



a b is a vector perpendicular to both
a and b, in the direction defined by
the right hand rule

a b = a b sin
a b = area of parallelogram ab
a b = 0 if a and b are parallel
Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 32


Example: Normal of a Triangle



Find

the unit length normal of the triangle defined by 3D points


a, b, and c

a

Interactive Computer Graphics, Spring 2013, University of Crete

b

Lecture 2: Linear Algebra in CG Slide 33

Example: Normal of a Triangle


n = (b a ) (c a )

n
n=
n

c

c-a

a

b-a

Interactive Computer Graphics, Spring 2013, University of Crete


b

Lecture 2: Linear Algebra in CG Slide 34

Example: Area of a Triangle



Find

the area of the triangle defined by 3D points a, b, and c


a

Interactive Computer Graphics, Spring 2013, University of Crete

b

Lecture 2: Linear Algebra in CG Slide 35

Example: Area of a Triangle



1
area = (b a ) (c a )
2
c

c-a

a

b-a

Interactive Computer Graphics, Spring 2013, University of Crete


b

Lecture 2: Linear Algebra in CG Slide 36

Example: Alignment to Target



An

object is at position p with a unit length heading of h.


We want to rotate it so that the heading is facing some
target t. Find a unit axis a and an angle to rotate around.

h

Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 37


Example: Alignment to Target



h ( t p)
a=
h ( t p)
a

t-p

$ h ( t p) '
1
)
= cos &&
)
h

p
(
)
%
(

t

h

Interactive Computer Graphics, Spring 2013, University of Crete

Lecture 2: Linear Algebra in CG Slide 38


Uses of the dot product


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 39


Rule for Dot product


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 40


Finding the length of a vector


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 41


Finding the
angle between
two vectors

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 42


More uses of
the Dot product

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 43


Summary: dot product and bases



Dot

product

u
v

Orthonormal

cos

basis

0, i j,
1, i j.

u
i uj
if

the basis vectors are mutually perpendicular, but not of unit length:
orthogonal

Orthonormal

Project
w

does not have to be simple vectors e.g. spherical harmonics


a vector orthogonally onto another vector:



uv
v

uv
vv

tv

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 44


Vector

cross product I

(cross) product

If

w
w

|uv|=|u||v|sin
u and w

u is parallel to v, cross product is 0


u,v,w

form a right-handed system


Properties



u v v u
au
bv w a u w
b v w
u v w v w u
u v w u w v u v w

Interactive Computer Graphics, Spring 2013, University of Crete


anti commutativity
linearity
scalar triple product
vector triple product

Lecture 2: Linear Algebra in CG Slide 45


Cross product
II

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 46


Linear Algebra: vector rules



(u+v)
u+v

+ w = u + (v + w) (associativity)

= v+u (commutativity)

+ v = v (zero identity, with zero vector 0 = (0,0,.0) )


+ (-v) = 0 (additive inverse)


Multiplication
(ab)u

by a scalar rules:

= a(bu)

(a+b)u

= au + bu (distributive law)

a(u+v)

= au + av (distributive law)

1u=u

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 47


Problem: Translating objects


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 48


What is a Matrix?

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 49


Translation

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 50


Scaling

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 51


Rotation

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 52


Sets of Linear
Equations and
Matrices

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 53


Matrix-Vector Multiplication I

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 54


Matrix-Vector Multiplication II

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 55


Algebraic
Properties of
Matrices

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 56


Matrix
multiplication
analyzed

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 57


Matrix
Inverse

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 58


What does
an Inverse
do?

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 59


Matrices (1/2)

A

tool for manipulating vectors 


and points

Identity

m00
m01
m10
m11
...
...
mp 1,0 mp 1,1

... m0,q 1
... m1,q 1
...
...
... mp 1,q 1

mij

matrix

Matrix-matrix

addition

Scalar-matrix

multiplication

Transpose:

1
0 ... 0
0
1 ... 0
... ... ... ...
0
0 ... 0
0
0 ... 1

M=[mij], MT=[mji]

M

Interactive Computer Graphics, Spring 2013, University of Crete


mij

nij mij

nij

Lecture 2: Linear Algebra in CG Slide 60


Matrices (2/2)

Matrix-Matrix
M

of size pxq and N qxr , T becomes pxr



m00
m10
...

T MN

mp

1,0

m01
m11
...
mp

1,1

Determinant
M

Inverse

n00
n10
...
np

n01
n11
...
np

1,0

... n0,r 1
... n1,r 1
...
...
... np 1,r 1

1,1

q 1
i0

q 1
i0

m0,i ni,0
...
...

mp

1,i

...
...
...

ni,0 ...

q 1
i0

q 1
i0

m0,i ni,r
...
...

mp

1,i

ni,r

of matrix M

m00 m11

m01 m10

of matrix M

Co-factor d

... m0,q 1
... m1,q 1
...
...
... mp 1,q 1

m00 m01
m10 m11

Adjoint

multiplication

dM02

m00 m01 m02


m10 m11 m12
m20 m21 m22

M
m10 m11
m20 m21

adj M

d00
d01
d02

d10
d11
d12

d20
d21
d22

of Matrix (use the formula below-left or Gauss-Jordan elimination below-right)



1
M

adj M
M

MI

MT

1 T

MN

Interactive Computer Graphics, Spring 2013, University of Crete


1
1

Lecture 2: Linear Algebra in CG Slide 61


Orthogonal Matrices

A

square matrix M, with only real elements and



T

MT M I
M 1


MM
M

MT

an orthogonal matrix is not the same as an orthogonal vector set


(mutually perpendicular vectors)

An
A

orthogonal matrix must consist of normalized vectors


rotation is an orthogonal matrix


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 62


Matrix
Notation

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 63


But, there is a problem


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 64


Solution to
notational
problem

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 65


Matrix Notation and Composition


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 66


Basic Trigonometry for CG I


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 67


Basic Trigonometry for CG II


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 68


Geometry: lines

r(t)

= o +td

is a point on the line


is direction of the line


is a parameter to generate
different points r on the line

ax+by+c=0

For

p to lie on lie L it must 


fulfill this equation

If

a,b are combined in vector


n=(nx,ny)=(a,b)

n.p

+ c =0

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 69


Geometry: Planes

Explicit

form: P(u,v)=o +us+vt


o is a point lying on the plane


s, t are direction vectors that span the plane (i.e. noncollinear)


u,v parameters to generate different points on the plane


Plane normal is sxt


Implicit

form: n.p + d=0


n is plane normal

P is a point on the plane


d is a constant that determines part of the position of the plane


f(p)=n.p + d

If f(p)=0, then p is on the plane


If f(p)>0, then p lies on the same side of the plane as q+n


If f(p)<0, then p lies on the same side of the plane as q-n


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 70


Geometry: Convex Hull



The

smallest set that


satisfies the following
condition:

The

straight line between


any two points in the set
is totally included in the set as well

Rubber
Used

band example

for bounding volume algorithms


Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 71


References

Dam,

A. 2003. Linear Algebra. Introduction to Computer


Graphics, CS Brown University, 153.

Akenine-Mller,

T., Haines, E., and Hoffman, N. 2008.


Appendix A. Some linear Algebra. Real-Time Rendering, 123.

Akenine-Mller,

T., Haines, E., and Hoffman, N. 2008.


Appendix B. Trigonometry. Real-Time Rendering, 17.

Rotenberg,

S., 2005, Vectors & Matrices, Computer Graphics,

UCSD

Interactive Computer Graphics, Spring 2013, University of Crete


Lecture 2: Linear Algebra in CG Slide 72


Thank you!

Interactive Computer Graphics, Spring 2013, University of Crete

Das könnte Ihnen auch gefallen