cs482: interactive computer graphicsvclab.kaist.ac.kr/cs482/slide04-affine.pdf · min h. kim...

26
Min H. Kim (KAIST) CS482: Interactive Computer Graphics CS482: Interactive Computer Graphics Min H. Kim KAIST School of Computing

Upload: others

Post on 20-Jul-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

CS482: Interactive Computer Graphics

Min H. KimKAIST School of Computing

Page 2: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

AFFINE TRANSFORMATION

2

Page 3: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Points vs. vectors• Vector := motion between points in space– lives in a space we call– has the structure of a linear/vector space.– addition and scalar multiplication have meaning– zero vector is no motion– cannot really translate motion

3

v

R3

Page 4: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Points vs. vectors• Point := a position in space– lives in a space we might call– has the structure of a so-called affine space.– addition and scalar multiplication don’t make sense– zero doesn’t make sense– subtraction does make sense, gives us a vector

4

pA3

Page 5: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Points and frames• Subtraction of points:

• Moving a point with a vector:

• Basis is three vectors

• How could we present translations?– Affine transform (4-by-4 matrix)– usage: transformation of objects and camera projection

(3D à 2D)

5

p − q =v

v = cibi

i∑

q +v = p

Page 6: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Points and frames• for affine space we will use a frame– start with a chosen origin point– add to it a linear combination of vectors using

coordinates to get to any desired point

6

o

ci p

Page 7: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Affine frame• Movement of a point (original à a point )

• Affine frame (made of three vectors and a point):

7

p = o+ cibi

i∑ = b1

b2

b3o⎡

⎣⎤⎦

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

!p = !o+ v".

o p

b1

b2

b3o⎡

⎣⎤⎦ = f t

p = f tc .

Page 8: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Defining an affine matrix• point is specified with a 4-coordinates vector– four numbers– last one is always 1– … or 0. (and we get a vector)

• let’s define an affine matrix as 4-by-4 matrix

• we are transforming a point to another with an affine frame:

8

a b c de f g hi j k l0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

!p = f" tc .

c1 c2 c3 1⎡⎣

⎤⎦t

Page 9: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Transforming a point• affine transform

9

b1

b2

b3o⎡

⎣⎤⎦

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

b1

b2

b3o⎡

⎣⎤⎦

a b c de f g hi j k l0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

Page 10: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Transforming a point• for short

• transforming coordinate vectors (4 with a one as the fourth entry)

10

p = f tc⇒ f tAc .

b1

b2

b3o⎡

⎣⎤⎦ = f t

c '1c '2c '31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

=

a b c de f g hi j k l0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

where

Page 11: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

transforming a point• Alternatively, transforming the basis vectors

• This transformation is to apply the affine transform to a frame as

11

b '1

b '2

b '3

o '⎡⎣

⎤⎦ = b1

b2

b3o⎡

⎣⎤⎦

a b c de f g hi j k l0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

b1

b2

b3o⎡

⎣⎤⎦⇒ b1

b2

b3o⎡

⎣⎤⎦

a b c de f g hi j k l0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

Page 12: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Linear transformation• 3-by-3 transform matrix à 4-by-4 affine

transform

12

b1

b2

b3o⎡

⎣⎤⎦

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

b1

b2

b3o⎡

⎣⎤⎦

a b c 0e f g 0i j k 00 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

Page 13: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Linear transformation• affine transformation:

where, L is a 4-by-4 matrix; l is a 3-by-3 matrix.• A linear transform is applied to a point. This is

accomplished by applying the linear transform to its offset vector.

13

L = l 00 1

⎣⎢

⎦⎥

Page 14: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Translation transform• translation transformation to points

14

b1

b2

b3o⎡

⎣⎤⎦

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

⇒ b1

b2

b3o⎡

⎣⎤⎦

1 0 0 tx0 1 0 ty0 0 1 tz0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

c1c2c31

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

Page 15: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Translation transform• translation transformation to points

• translation matrix

• where, T is a 4-by-4 matrix; i is a 3-by-3 identity matrix, t is 3-by-1 matrix for translation.

15

c1 ⇒ c1 + txc2 ⇒ c2 + tyc3 ⇒ c3 + tz

T = i t0 1

⎣⎢

⎦⎥

Page 16: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Affine transform matrix• An affine matrix can be factored into a linear

part and a translational part:

16

a b c de f g hi j k l0 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

=

1 0 0 d0 1 0 h0 0 1 l0 0 0 1

⎢⎢⎢⎢

⎥⎥⎥⎥

a b c 0e f g 0i j k 00 0 0 1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

.

l t0 1

⎣⎢

⎦⎥ =

i t0 1

⎣⎢

⎦⎥

l 00 1

⎣⎢

⎦⎥ A = TL

Page 17: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Affine transform matrix• NB as matrix multiplication is not commutative,

the order of the multiplication TL matters!!!

• Since these matrices have the same size (4-by-4), it is difficult to debug when you messed up the order. Pay extra attention on it while you are coding…

17

TL ≠ LT

Page 18: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Rigid body transformation• When the linear transform is a rotation, we call

this as rigid body transformation (rotation + translation only).

• A rigid body transformation preserves dot product between vectors, handedness of a basis, and distance between points.

• Its geometric topology is maintained while transforming it.

18

A = TR

Page 19: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Affine transform acting on vector• If fourth coordinate of c is zero, this just

transforms a vector to a vector.– note that the fourth column is irrelevant– a vector cannot be translated

19

Page 20: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Normals• Normal: a vector that is orthogonal to the

tangent plane of the surfaces at that point.– the tangent plane is a plane of vectors that are

defined by subtracting (infinitesimally) nearbysurface points:

20

n ⋅( p1 − p2 ) = 0

Page 21: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Normals• We use normals for shading• how do they transform• suppose i rotate forward– normal gets rotated forward

• suppose squash in the y direction

21

Page 22: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Changing a shape• Squashing a sphere makes its normals stretch

along the y axis instead of squashing.

• normal gets higher in the y direction• what is the rule?

22

nxnynz

⎢⎢⎢

⎥⎥⎥≠

nx 'ny 'nz '

⎢⎢⎢

⎥⎥⎥.

Page 23: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Transforming normals• Since the normal and very close points and

are on a surface:

• After applying an affine transform A,

23

nx ny nz ∗⎡⎣

⎤⎦

x1y1z11

⎢⎢⎢⎢

⎥⎥⎥⎥

x0y0z01

⎢⎢⎢⎢

⎥⎥⎥⎥

⎜⎜⎜⎜

⎟⎟⎟⎟

= 0 .

n p1 p2

nx ny nz ∗⎡⎣

⎤⎦A

−1( ) A

x1y1z11

⎢⎢⎢⎢

⎥⎥⎥⎥

x0y0z01

⎢⎢⎢⎢

⎥⎥⎥⎥

⎜⎜⎜⎜

⎟⎟⎟⎟

⎜⎜⎜⎜

⎟⎟⎟⎟

= 0 .

the normal of the transformed geometry

n ⋅( p1 − p2 ) = 0

Page 24: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Transforming normals

• Transformed normals (l = rotation + scaling):

• Transposing this expression (the scale of the inverse transpose of l is different from l):

24

nx ' ny ' nz '⎡⎣

⎤⎦ = nx ny nz⎡

⎣⎤⎦ l

−1 .

nx 'ny 'nz '

⎢⎢⎢

⎥⎥⎥= l− t

nxnynz

⎢⎢⎢

⎥⎥⎥.

x ' y ' z ' 1⎡⎣

⎤⎦t= A x y z 1⎡

⎣⎤⎦t

nx ' ny ' nz ' *⎡⎣

⎤⎦ = nx ny nz 1⎡

⎣⎤⎦A

−1

R− t = R, RtR = I(R is a pure rotation only)

Page 25: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Normal vs. Object transformation • If we have a pure rotation only, the pure rotation

only transformation keeps the same scale of normals!

• But the inverse transpose of the object transformation keeps the same rotation of normalsbut its scale is changed inversely!

• In summary, – after applying the inverse transpose linear transform to

the normals of the object’s affine transformation,– We need to normalize (resize) the normal!!!

25

R− t = R, RtR = I

Page 26: CS482: Interactive Computer Graphicsvclab.kaist.ac.kr/cs482/slide04-Affine.pdf · Min H. Kim (KAIST) CS482: Interactive Computer Graphics Points vs. vectors •Point := a position

Min H. Kim (KAIST) CS482: Interactive Computer Graphics

Transforming normals• Renormalize to correct unit normals of squashed

shape:

26

Before Affine transformAfter Affine transform to normals

(not normalized normals)After Affine transform (normalized normals)