geometric transforms - fabio...

54
geometric transforms 1

Upload: others

Post on 12-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

geometric transforms

1

Page 2: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

linear algebra review

2

Page 3: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

matrices

matrix and vector notation

use column for vectors

M = [ ] = [ ]m11

m21

m12

m22mij

v = [ ] =v1

v2[ ]v1 v2

T

3

Page 4: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

matrix operations

addition

scalar multiplication

T = M + N

[ ] = [ ]tij +mij nij

T = aM

[ ] = [ ]tij amij

4

Page 5: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

matrix operations

matrix-matrix multiplication

row-column multiplication

not commutative

associative

T = MN = [ ] = [ ]tij ∑k

miknkj

=⎡⎣⎢⎢

t11

t21

t12

t22

⎤⎦⎥⎥

⎡⎣⎢⎢

m11

m21

m12

m22

⎤⎦⎥⎥⎡⎣⎢⎢

n11

n21

n12

n22

⎤⎦⎥⎥

5

Page 6: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

matrix operations

matrix-vector multiplication

row-column multiplication

u = Mv

=⎡⎣⎢⎢

u1

u2

⎤⎦⎥⎥

⎡⎣⎢⎢

m11

m21

m12

m22

⎤⎦⎥⎥⎡⎣⎢⎢

v1

v2

⎤⎦⎥⎥

6

Page 7: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

matrix operations

transpose: flip along diagonal

inverse (not computed explicitly in this course)

T = MT

[ ] = [ ]tij tji

T = M−1

MT = M = M = IM−1 M−1

7

Page 8: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

special matrices

identity: invariant for multiplication

I = [ ] = {iij10

i = ji ¡ j

I = [ ]10

01

:M : M = MI = IM

8

Page 9: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

special matrices

zero: invariant for addition

O = [ ] = 0iij

I = [ ]00

00

:M : M = M + O = O + M

9

Page 10: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

matrix operation properties

linearity of multiplication and addition

associativity of multiplication

a(A + B) = aA + aB

M(aA + bB) = aMA + bMB

A(BC) = (AB)C

10

Page 11: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

matrix operation properties

transpose and inverse of multiplication

(AB =)T BT AT

(AB =)−1 B−1A−1

11

Page 12: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

2d transformation

12

Page 13: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

geometric transformations

functions that maps points to points

different transformations have restrictions on the form of

p Ü = X(p)p′

X

13

Page 14: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

translation

(p) = p + tTt

(p) = (p) = p − tT −1t T−t

14

Page 15: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

linear transformations

fundamental property:

can be represented in matrix form:

properties:

maps origin to origin

maps lines to lines

parellel lines remain parallel

length ratios are preserved

closed under composition

X(ap + bq) = aX(p) + bX(q)X(p) = Mp

15

Page 16: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

uniform scale

p = [ ][ ] = [ ]Sss0

0s

pxpy

spxspy

=S−1s S1/s

16

Page 17: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

non-uniform scale

p = [ ][ ] = [ ]Sssx

00sy

pxpy

sxpxsypy

=S−1s S1/s

17

Page 18: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

rotation

p = [ ][ ] = [ ]R?cos ?sin ?

− sin ?cos ?

pxpy

cos ? − sin ?px py

sin ? + cos ?px py

=R−1? R−?

18

Page 19: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

shear

S p = [ ][ ] = [ ]hs1sy

sx

1pxpy

+px sxpy

+sypx py

19

Page 20: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

reflection

R p = [ ][ ] = [ ] R p = )lx−10

01

pxpy

−pxpy

ly

R p = [ ][ ] = [ ]lo−10

0−1

pxpy

−px−py

20

Page 21: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

affine transforms

combine translation with linear transformation

rigid body transformation are a subset of this

properties

does not map origin to origin

maps lines to lines

parallel lines remain parallel

length ratios are preserved

closed under composition

(p) = Mp + tXM,t

21

Page 22: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transforming points and vectors

points and vectors are different entities

vectors: encode direction and length (difference of points)

points: encode position (origin plus a vector)

points: transform as reported above

vectors: transform like points, but no translation is applied

directions (normalized vectors): normalize after transform

X(p) = Mp + t

X(v) = Mv

X( ) = M /| M |d̂ d̂ d̂

22

Page 23: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transforming points and vectors

proof that vectors transform as such

vX(p)X(v)

= p − q= Mp + t= X(p) − X(q) == (Mp + t) − (Mq + t) == M(p − q) == Mv

23

Page 24: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

homogeneous coordinates

represent points/vectors with an additional coordinate

set it to 1 for points (or multiply all per arbitrary )

set it to 0 for vectors

ww

p = ¢⎡

⎣⎢⎢

pxpy

1

⎦⎥⎥

⎣⎢⎢

wpxwpy

w

⎦⎥⎥

v =⎡

⎣⎢⎢

vx

vy

0

⎦⎥⎥

24

Page 25: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

homogeneous coordinates

translation: represent as 3x3 matrix

shorthand notation for points and vectors

p = =Tt

⎣⎢⎢

100

010

tx

ty

1

⎦⎥⎥⎡

⎣⎢⎢

pxpy

1

⎦⎥⎥

⎣⎢⎢

+px tx

+py ty

1

⎦⎥⎥

p = [ ][ ] = [ ]TtI0

t1

p1

p + t1

v = [ ][ ] = [ ]TtI0

t1

v0

v0 25

Page 26: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

homogeneous coordinates

linear transform: 3x3 matrix by adding one row,column

shorthand notation for points and vectors

Mp = =⎡

⎣⎢⎢

m11

m21

0

m12

m22

0

001

⎦⎥⎥⎡

⎣⎢⎢

pxpy

1

⎦⎥⎥

⎣⎢⎢

+m11px m12py

+m21px m22py

1

⎦⎥⎥

Mp = [ ][ ] = [ ]M0

01

p1

Mp1

Mv = [ ][ ] = [ ]M0

01

v0

Mv0 26

Page 27: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

affine transformations

combine linear and translation in one matrix

Xp = [ ][ ] = Mp + tM0

t1

p1

Xv = [ ][ ] = MvM0

t1

v0

27

Page 28: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

combining transforms

apply one transformation after the another

express by function composition

for affine transformations, compute by matrix multiplication

= ( (p)) = ( Q (p))p′ X2 X1 X2 X1

( Q (p)) = ( (p)) = ( )p = ( )pX2 X1 X2 X1 M2 M1 M2M1

28

Page 29: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

combining transforms

translation

linear transformations

[ ][ ] = [ ]I0

t2

1I0

t1

1I0

+t1 t2

1

[ ][ ] = [ ]M2

001

M1

001

M2 M1

001

29

Page 30: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

combining transforms

affine transformations

[ ][ ] = [ ]M2

0t2

1M1

0t1

1M2M1

0+M2 t1 t2

1

30

Page 31: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

composition is not commutative

original rotation translation

original transation rotation 31

Page 32: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

complex transformations

represent as combination of simpler ones

intuitive geometric interpretation

rotation around arbitrary axis at of angle

translate axis center to origin

rotate (about origin)

translate back

a ?

=Ra,? TaR?T−a

32

Page 33: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

complex transformations

33

Page 34: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

complex transformations

34

Page 35: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transforms and coordinate systems

change of coordinate system can be written as affine matrix

for , we have

that in matrix form becomes

Ü ff ′ p = + + +f ′O p′

xf ′x p′

xf ′y p′

xf ′z

p = [ ][ ] = [ ][ ]M0

t1

p′

1f ′

x

0

f ′y

0

f ′z

0

f ′o

1p′

1

35

Page 36: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transforms and coordinate systems

for , we invert the previous equation

since is orthonormal,

f Ü f ′

= [ ][ ]p′ M−1

0tM −1

1p1

M =M −1 MT

=p′

⎢⎢⎢⎢

x′T

y′T

z′T

0

˝ tx′

˝ ty′

˝ tz′

1

⎥⎥⎥⎥

⎢⎢⎢⎢

pxpy

pz

1

⎥⎥⎥⎥

36

Page 37: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

3d transformations

37

Page 38: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

3d transformations

adopt homogeneous formulation in 3d

point have 4 coordinates

use 4x4 matrices for transformations

most concepts generalize very easily

rotation much more complex

38

Page 39: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

translation

=Tt

⎢⎢⎢⎢

1000

0100

0010

txty

tz

1

⎥⎥⎥⎥

39

Page 40: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

scale

=Ss

⎢⎢⎢⎢

sx

000

0sy

00

00sz

0

0001

⎥⎥⎥⎥

40

Page 41: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

rotation around z

=Rz?

⎢⎢⎢

cos ?sin ?

00

−sin ?cos ?

00

0010

0001

⎥⎥⎥

41

Page 42: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

rotation around y

=Ry?

⎢⎢⎢

cos ?0

−sin ?0

0100

sin ?0

cos ?0

0001

⎥⎥⎥

42

Page 43: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

rotation around x

=Rx?

⎢⎢⎢

1000

0cos ?sin ?

0

0−sin ?cos ?

0

0001

⎥⎥⎥

43

Page 44: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

rotation around arbitrary axis

in 2D, rotation are around a point:

change coordinate frame (translation)

rotation around the origin

change coordinate frame back

simple geometric construction

in 3D, rotation are around an axis:

change coordinate frame (align with axis )

rotation around

change coordinate frame back

complex geometric construction

=Ra,? TaR?T−a

=Ra,? F−1aR?Fa

z az

44

Page 45: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

representing rotations

Euler angles: 3 rotations around major axis

remember to choose order

simple but has quirks when combining rotations

will use this for simplicity

axis and angle

combinations of rotations can be represented this way

with more formalism become elegant and consistent

quaternions

45

Page 46: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transforming normals

points and vectors works

tangents, i.e. differences of points, work too

normals works differently

defined as orthogonal to the transformed surface

i.e. orthogonal to all tangents

46

Page 47: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transforming normals

by definition:

after tranform:

for all we have:

which gives:

normals are transformed by the inverse transpose

t ˝ n = n = 0tT

(Mt (Xn) = 0)T

t Xn = 0tT M T

( n = 0tT M T MT )−1

47

Page 48: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transformation hierarchies

48

Page 49: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transformation hierarchies

often need to transform an object wrt another

e.g. the computer on the table

when the table moves, the computer moves

naturally build a hierarchy of transformation

to transform the table, apply its transform

to transform the computer, apply the table and the

computer transform

49

Page 50: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transformation hierarchies

represented as a tree data structure

transformation nodes

object nodes / leaves

walk the tree when drawing

very convenient representation for objects

all objects can be defined in their simplest form

e.g. every sphere can be represented by a transformation

applied to the unit sphere

50

Page 51: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

transformation hierarchies

51

Page 52: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

implementing transform hierarchies

transformation function for each node

get the parent matrix

multiply the parent and current matrices

pass the combined matrix when calling children

stack of transforms

push/pop when walking down/up

used by graphics libraries (OpenGL)

more flexible

generalized mechanism for all attributes

52

Page 53: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

raytracing and transformations

transform the object

simple for triangles, since they transforms to triangles

but most objects require complex intersection tests

spheres do not transforms to spheres, but ellipsoids

transform the ray

much more elegant

works on any surface

allow for much simpler intersection tests

only worry about unit sphere, all others are transformed

53

Page 54: geometric transforms - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/04_transforms.pdf · geometric transformations functions that maps points to points different

raytracing and transformations

transforming rays

transform origin/direction as point/vector

note that direction is not normalized now

i.e. ray parameter is not the distance

intersect a transformed object

transform the ray by matrix inverse

intersect surface

transform hit point and normal by matrix

works like changes in coodinate system

54