114
CS-C3100 Fall 2016 – Lehtinen Coordinate Transformations & Homogeneous Coordinates CS-C3100 (Introduction to) Computer Graphics Jaakko Lehtinen Lots of slides from Frédo Durand

Coordinate Transformations & Homogeneous Coordinates

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Coordinate

Transformations & Homogeneous

Coordinates

CS-C3100 (Introduction to) Computer Graphics Jaakko Lehtinen

Lots of slides from Frédo Durand

Page 2: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 2

Outline• Intro to Transformations • Useful Classes of Transformations • Representing Transformations,

Homogeneous Coordinates • Combining Transformations • Hardcore: Transforming normals

Page 3: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Pipeline Recap

3

1.Model the geometry • Here a triangle mesh. • Also, specify materials.

Page 4: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Pipeline Recap

4

1.Model the geometry • Here a triangle mesh. • Also, specify materials.

Object coordinates

Page 5: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Pipeline Recap

5

1.Model the geometry 2.Place the objects in

world space • Each object has its own

object space • Only one world space

Object coordinates World coordinates

Object Another Object

World Origin

Page 6: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Pipeline Recap

6

1.Model the geometry 2.Place the objects in

world space 3.Pick viewing position

and direction

Object coordinates World coordinates View coordinates

Camera position and orientation

Page 7: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Pipeline Recap

7

1.Model the geometry 2.Place the objects in

world space 3.Pick viewing

position and direction 4.Transform objects to

view space and project to image plane • Compute shading

Object coordinates World coordinates View coordinates Image coordinates

Page 8: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Summary

Object coordinates

World coordinates

View coordinates

Image coordinates

Today we’ll look at the transformations that take us between these coordinates.

Page 9: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Questions?

9

Page 10: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 10

What is a Transformation?• A function that maps point x to point x':

Applications: animation, deformation, viewing, projection, real-time shadows, …

From Sederberg and Parry, Siggraph 1986

Page 11: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 11

Simple Transformations

?

Page 12: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 12

Simple Transformations

• Can be combined • Are these operations invertible?

Yes, except scale = 0

Page 13: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Questions?

13

Page 14: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 14

Outline• Intro to Transformations • Useful Classes of Transformations

– This is the stuff you use for most modeling/viewing • Representing Transformations,

Homogeneous Coordinates • Combining Transformations • Transforming Normals

Page 15: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 15

Rigid-Body / Euclidean Transforms

• What properties are preserved?

TranslationRotation

Rigid / Euclidean

Identity

Page 16: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 16

Rigid-Body / Euclidean Transforms

• Preserves distances • Preserves angles

TranslationRotation

Rigid / Euclidean

Identity

Page 17: Coordinate Transformations & Homogeneous Coordinates

• Preserves angles • “The shapes are the same”, just

at different scale, orientation and location

CS-C3100 Fall 2016 – Lehtinen 17

Similitudes / Similarity Transforms

TranslationRotation

Rigid / Euclidean

Similitudes

Isotropic ScalingIdentity

Page 18: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 18

Linear Transformations

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic ScalingIdentity

Scaling

Shear

Reflection

Page 19: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 19

Linear Transformations

• L(p + q) = L(p) + L(q) • L(ap) = a L(p)

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic Scaling

Scaling

Shear

ReflectionIdentity

Page 20: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 20

Linear Transformations

• L(p + q) = L(p) + L(q) • L(ap) = a L(p)

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic Scaling

Scaling

Shear

ReflectionIdentity

???

Page 21: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 21

Linear Transformations

• L(p + q) = L(p) + L(q) • L(ap) = a L(p)

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic Scaling

Scaling

Shear

ReflectionIdentity

???

Translation is not linear: f(p) = p+t

f(ap) = ap+t ≠ a(p+t) = a f(p) f(p+q) = p+q+t ≠ (p+t)+(q+t) = f(p) + f(q)

Page 22: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 22

Affine Transformations

• What is preserved..?

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic Scaling

Scaling

Shear

ReflectionIdentity

Affine

Page 23: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 23

Affine Transformations

• Preserves parallel lines

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic Scaling

Scaling

Shear

ReflectionIdentity

Affine

Page 24: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 24

Projective Transformations• Preserves lines: lines remain lines

(planes remain planes in 3D)

TranslationRotation

Rigid / EuclideanLinear

Affine

(Planar) Projective

Similitudes

Isotropic Scaling

Scaling

Shear

Reflection

Perspective

Identity

Page 25: Coordinate Transformations & Homogeneous Coordinates

• What’s with the hierarchy? Why have we grouped types of transformations with and within each other?

CS-C3100 Fall 2016 – Lehtinen 25

What’s so nice about these?

TranslationRotation

Rigid / Euclidean

LinearAffine(Planar) Projective

Similitudes

Isotropic Scaling

Scaling

ShearReflection

Perspective

Identity

Page 26: Coordinate Transformations & Homogeneous Coordinates

• They are closed under concatenation – Means e.g. that an affine transformation followed by

another affine transformation is still an affine transformation

– Same for every subgroup, e.g. rotations, translations..

• Very convenient! • Projections are the

most general – Others are its

special casesCS-C3100 Fall 2016 – Lehtinen 26

What’s so nice about these?

TranslationRotation

Rigid / Euclidean

LinearAffine(Planar) Projective

Similitudes

Isotropic Scaling

Scaling

ShearReflection

Perspective

Identity

Page 27: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Name-dropping

27

• Fancy name: Group Theory • Remember algebra?

– A group is a set S with an operation f that takes two elements of S and produces a third: (and some other axioms)

• These transformations are group(s) and subgroups – The transformations are the set S,

concatenation of transformations is f

s, t ⇥ S, f(s, t) = u � u ⇥ S

Page 28: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Transforms are Groups

28

• Why is this useful? – You can represent any number of

successive transformations by a single compound transformation

• Example – The object-to-world transformation,

the world-to-view transformation, and the perspective projection (view-to-image) can all be folded into a single projective object-to-image transformation

– (OpenGL: Modelview, projection)

Disclaimer:Not ANY

transformation, but the types

just introduced

Object coordinates World coordinates View coordinates Image coordinates

Page 29: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Questions?

29

Page 30: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

More Complex Transformations..

30

• ...can be built out of these, e.g.

• Skinning – Blending of affine

transformations – We’ll do this later! – And you will code

it up! :) Ilya Baran

Page 31: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

More Complex Transformations

31

• Harmonic coordinates (link to paper) – Object enclosed in simple “cage”, each object point

knows the influence each cage vertex has on it – Deform the cage, and the object moves!

Pix

ar

Page 32: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 32

Questions?

Page 33: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 33

Outline• Intro to Transformations • Useful Classes of Transformations • Representing Transformations,

Homogeneous Coordinates • Combining Transformations • Transforming Normals

Page 34: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Interlude: ImmersiveMath.com

34

• If your matrices and vectors are a little rusty, and even if they aren’t, read the first chapters from this really neat interactive linear algebra “book”!

Page 35: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 35

How are Linear Transforms Represented?

Linear transformations include rotation, scaling,

reflection, and shear

Page 36: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 36

How are Linear Transforms Represented?

x' = ax + by y' = dx + ey

Linear transformations include rotation, scaling,

reflection, and shear

Page 37: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 37

How are Linear Transforms Represented?

x' y'

a b d e=

x y

p' = M p

x' = ax + by y' = dx + ey

Linear transformations include rotation, scaling,

reflection, and shear

Page 38: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 38

How are Linear Transforms Represented?

x' y'

a b d e=

x y

p' = M p

x' = ax + by y' = dx + ey

Linear transformations include rotation, scaling,

reflection, and shear

Note that the origin always stays fixed.

Page 39: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 39

How are Affine Transforms Represented?

x' = ax + by + c y' = dx + ey + f

x' y'

a b d e

c f=

x y

+

p' = M p + t

Affine transformations include all linear

transformations, plus translation

Page 40: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 40

Can we use matrices for affine transforms?

x' = ax + by + c y' = dx + ey + f

p' = M p ?

x' y'

a b d e=

x y

p' = M p

Page 41: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 41

The Homogeneous Coordinate Trickx' = ax + by + c y' = dx + ey + f

x y 1

x' y'

a b d e

c f=

x y

+

p' = M p + t

Affine formulation Homogeneous formulation

This is whatwe want:

Page 42: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 42

x' = ax + by + c y' = dx + ey + f

x' y‘ 1

a b d e 0 0

c f 1

=x y 1

p' = M p

x' y'

a b d e

c f=

x y

+

p' = M p + t

Affine formulation Homogeneous formulation

This is whatwe want:

The Homogeneous Coordinate Trick

Page 43: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 43

Homogeneous Coordinates• Add an extra dimension

– in 2D, we use 3-vectors and 3 x 3 matrices – In 3D, we use 4-vectors and 4 x 4 matrices – Makes affine transformations linear in one higher

dimension (can be represented by a matrix) • Each point has an extra value, w

– You can think of it as “scale” – For all transformations except

perspective, you can just set w=1 and not worry about it

x' y‘ 1

a b d e 0 0

c f 1

=x y 1

Page 44: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 44

Homogeneous Coordinates

• If we multiply a homogeneous point by an affine matrix, w is unchanged – “Affine matrix” means the last row is (0 0 0 1) – This form encodes all possible affine transformations! – What happens when you multiply an affine matrix with

another affine matrix?

x' y' z' 1

=

x y z 1

a e i 0

b f j 0

c g k 0

d h l 1

Page 45: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

More on w

45

• As mentioned, you can think of it as “scale”. • Let’s see:

x' y' 1

a b d e 0 0

c f 1

=x y 1

? a b d e 0 0

c f 1

=2x 2y 2

Page 46: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

More on w

46

• As mentioned, you can think of it as “scale”. • Let’s see:

x' y' 1

a b d e 0 0

c f 1

=x y 1

(DUH!)2x' 2y' 2

a b d e 0 0

c f 1

=2x 2y 2

Page 47: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

More on w

47

• As mentioned, you can think of it as “scale”. • Let’s see:

x' y' 1

a b d e 0 0

c f 1

=x y 1

2x' 2y' 2

a b d e 0 0

c f 1

=2x 2y 2

(DUH!)It’s tempting to

divide by w, because this will get us back to

the result above.

Page 48: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

“Projective Equivalence” in 1D

48

w=0

w=1

w=2

w=3

w

x (0,0)

(x,w)

Page 49: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Projective Equivalence in 1D

49

• We can get into a “canonical form” by dividing by w. This projects (x, w) onto the line w=1 yielding (x/w, 1).

w=0

w=1

w=2

w=3

w

x (0,0)

(x,w)

(x/w,1)

Page 50: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Projective Equivalence in 1D

50

• We can get into a “canonical form” by dividing by w. This projects (x, w) onto the line w=1 yielding (x/w, 1).

• We say that all points on dashed line are identical becausethey project to the same point on the line w=1.

w=0

w=1

w=2

w=3

w

x (0,0)

(x,w)

(x/w,1)

Page 51: Coordinate Transformations & Homogeneous Coordinates

• More mathematically, all non-zero scalar multiples of a point are considered identical • So, in fact, we are saying that points in ND are

identified with lines through the origin in (N+1)D

CS-C3100 Fall 2016 – Lehtinen

Projective Equivalence

51

x y z w

ax ay az aw

a != 0

=x/w y/w z/w 1

=w !=0

Page 52: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 52

Homogeneous Visualization in 2D• Divide by w to normalize (project)

w = 1

w = 2

(0, 0, 1) = (0, 0, 2) = …(7, 1, 1) = (14, 2, 2) = …(4, 5, 1) = (8, 10, 2) = …

(0,0,0)

Page 53: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 53

Homogeneous Visualization in 2D• Divide by w to normalize (project) • w = 0?

w = 1

w = 2

(0, 0, 1) = (0, 0, 2) = …(7, 1, 1) = (14, 2, 2) = …(4, 5, 1) = (8, 10, 2) = …

Points at infinity (directions)

(0,0,0)

Page 54: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Projective Equivalence – Why?

54

• For affine transformations, adding w=1 in the end proved to be convenient.

• The real showpiece is perspective.

Page 55: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Projective Equivalence – Why?

55

• For affine transformations, adding w=1 in the end proved to be convenient.

• The real showpiece is perspective. – From the camera’s point of view, all 3D points on the

line fall on the same 2D coordinate in the image. – In that sense, all those 3D points are

“identical”.

Page 56: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 56

Questions?

Page 57: Coordinate Transformations & Homogeneous Coordinates

• Why bother with the extra dimension? – Because now translations

can be encoded in the matrix!

CS-C3100 Fall 2016 – Lehtinen 57

x' y' z' 1

Translate (tx, ty, tz)

x' y' z'

=

x y z 1

1 0 0 0

0 1 0 0

0 0 1 0

tx

ty

tz

1

Translate(c,0,0)

x

y

p p'

c

Page 58: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

What’s Actually Happening?

58

x' = x + c

x x’

c

Page 59: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

What’s Actually Happening?

59

x' = x + c

c

(x,1) (x’,1)

Let’s first add the 2nd dimension w and set coordinates to 1. What does this mean..?

Page 60: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 60

w=1

w=2

w=0(0,0)

x' = x + c

x

w

What’s Actually Happening?

(x,1) (x’,1)

xx’

Page 61: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 61

w=1

w=2

w=0(0,0)

x' = x + c

x

w

What’s Actually Happening?xx’

Page 62: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 62

w=1

w=2

w=0(0,0)x

w

x' 1

1 c 0 1=

x 1

What’s Actually Happening?xx’

Page 63: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

What’s Actually Happening?

63

w=1

w=2

w=0(0,0)

x' 1

1 c 0 1=

x 1

It’s a 2D shear!

This line stays put, and origin stays still

x

w

x

w

Page 64: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 64

Questions?

Page 65: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 65

Scale (sx, sy, sz)• Isotropic (uniform)

scaling: sx = sy = sz

x' y' z' 1

=

x y z 1

sx

0 0 0

0 sy

0 0

0 0 sz

0

0 0 0 1

Scale(s,s,s)

x

p

p'

qq'

y

Page 66: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 66

Rotation• About z axis

x' y' z' 1

=

x y z 1

cos θ sin θ

0 0

-sin θ cos θ

0 0

0 0 1 0

0 0 0 1

ZRotate(θ)

x

y

z

p

p'

θ

Page 67: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 67

Rotation• About (kx, ky, kz), a unit

vector on an arbitrary axis (Rodrigues Formula)

x' y' z' 1

=

x y z 1

kxkx(1-c)+c kykx(1-c)+kzs kzkx(1-c)-kys

0

0 0 0 1

kxky(1-c)-kzs kyky(1-c)+c

kzky(1-c)+kxs 0

kxkz(1-c)+kys kykz(1-c)-kxs kzkz(1-c)+c

0

where c = cos θ & s = sin θ

Rotate(k, θ)

x

y

z

θ

k

Page 68: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Rotations and Matrices

68

• Rotations are represented by orthonormal matrices, i.e., matrices such that MTM = I – This implies det(M) = ±1 (why?) – Furthermore, to rule out reflections, require det(M)=1

• Rotations are a group of their own – Can you prove this based on the above properties?

Page 69: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 69

Questions?

Page 70: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

A Word of Warning

70

• In “regular” 3D, adding a displacement d to a point p is simple

• What about homogeneous coordinates?

p� = p + d =

⇤px + dx

py + dy

pz + dz

p� =

⇧⇧⇤

px

py

pz

1

⌃⌃⌅ +

⇧⇧⇤

dx

dy

dz

⌃⌃⌅?

Page 71: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

A Word of Warning

71

• In “regular” 3D, adding a displacement d to a point p is simple

• What about homogeneous coordinates?

p� = p + d =

⇤px + dx

py + dy

pz + dz

0p� =

⇧⇧⇤

px

py

pz

1

⌃⌃⌅ +

⇧⇧⇤

dx

dy

dz

⌃⌃⌅ =

⇧⇧⇤

px + dx

py + dy

pz + dz

1

⌃⌃⌅

You can’t add homogeneous points to each

other like in 3D.

Page 72: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

A Word of Warning

72

• In 3D, adding a displacement d to a point p is simple

• What about homogeneous coordinates?

p� = p + d =

⇤px + dx

py + dy

pz + dz

0p� =

⇧⇧⇤

px

py

pz

1

⌃⌃⌅ +

⇧⇧⇤

dx

dy

dz

⌃⌃⌅ =

⇧⇧⇤

px + dx

py + dy

pz + dz

1

⌃⌃⌅

w stays the same!

px' py' pz' 1

=

px py pz 1

1 0 0 0

0 1 0 0

0 0 1 0

dx

dy

dz

1

You can’t add homogeneous points to each

other like in 3D.

Page 73: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

The Same for Scaling

73

a p =

⇧⇧⇤

a px

a py

a pz

a

⌃⌃⌅Remember projective

equivalence

Page 74: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

The Same for Scaling

74

• You also leave w fixed.

a p =

⇧⇧⇤

a px

a py

a pz

1

⌃⌃⌅

Page 75: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Summary

75

• Affine n-D transformations are encoded by linear transformations in (n+1)D that move corresponding homogeneous points in the w=1 (hyper)plane – Technically, w=any constant works too, just have to

scale translation distances as well.

Important!

Page 76: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 76

Questions?

Page 77: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Why Bother II: Perspective

w = 1

w = 2

77

• This picture gives away almost the whole story.

Page 78: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Perspective in 2D

78

• Camera at origin, looking along z, 90 degree f.o.v., “image plane” at z=1

z=1

z=0xz

p=(x,z)

p’=(x/z,1)

(0,0)

x=zx=-z

Page 79: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Perspective in 2D

79

z=1

z=0xz

p=(x,z)

p’=(x/z,1)

(0,0)

x=zx=-z

p� =

⇤x/z11

⌅The projected point in

homogeneous coordinates

(we just added w=1):

Page 80: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Perspective in 2D

80

z=1

z=0xz

p=(x,z)

p’=(x/z,1)

(0,0)

x=zx=-z

p� =

⇤x/z11

⌅ �

⇤xzz

Projectively equivalent

Page 81: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

How do you do this with a matrix?

81

0

@x

z

z

1

A =

0

@ ?

1

A

0

@x

z

1

1

A

Page 82: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Perspective in 2D

82

z=1

z=0xz

p=(x,z)

p’=(x/z,1)

(0,0)

x=zx=-z

p� �

⇤xzz

⌅ =

⇤1 0 00 1 00 1 0

⇤xz1

⌅ ,

We’ll just copy z to w, and get the

projected point after homogenization!

Page 83: Coordinate Transformations & Homogeneous Coordinates

⇧⇧⇤

x�

y�

z�

w�

⌃⌃⌅ =

⇧⇧⇤

1 0 0 00 1 0 00 0 1 00 0 1 0

⌃⌃⌅

⇧⇧⇤

xyz1

⌃⌃⌅

CS-C3100 Fall 2016 – Lehtinen

Extension to 3D

83

• Trivial:Just add another dimension y and treat it like x – z is the special one, it turns into w’

• Different fields of view and non-square image aspect ratios can be accomplished by simple scaling of the x and y axes.

Page 84: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Caveat

84

• These projections matrices work perfectly in the sense that you get the proper 2D projections of 3D points.

• However, since we are flattening the scene onto the z=1 plane, we’ve lost all information about the distance to camera. – Not a big deal for ray tracers, but GPUs need distances

for “Z buffering”, i.e., figuring out what is in front of what.

Page 85: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

The “View Frustum” in 2D

85

• (In 3D this would be a truncated pyramid.)

z=1

z=far

z=0xz

p

(0,0)

z=near

z’=1

z’=0x’z’

p’q

q’

x’=-1 x’=1

Page 86: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

The View Frustum in 2D

86

• We can transform the frustum by a modified projection in a way that makes it a square after projection and homogenization (division by w).

⇤x⇤

z⇤

w⇤

⌅ =

⇤1 0 00 f+n

f�n � 2⇥f⇥nf�n

0 1 0

⇤xz1

⌅ ,

xz

x’/w’

z’/w’

These z’/w’ values

go into the Z buffer.

Page 87: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Details in Handout in MyCourses

87

• “Understanding Projections and Homogenous Coordinates” – How you get the matrix from previous slide

• Fun demonstration: Print the following page out. Holding the paper as flat as possible, try to see if you can hold it at such an angle in front of you so that the grid looks like a square with a regular grid in it.

Page 88: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 88

Page 89: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 89

Cool Application Video• “Structure from Motion” -algorithms

– SfM if a branch of computer vision that tries to understand the 3D structure of the scene from pictures taken from different viewpoints.

– It’s all based on projective geometry and homogeneous coordinates.

– Examples: • http://phototour.cs.washington.edu/ • http://phototour.cs.washington.edu/findingpaths/

Page 90: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Want to Know More?

90

• Take Ville Kyrki’s Machine Perception (AS-84.3126) to know more!

Page 91: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 91

Page 92: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 92

Phase 3: Profit• All these are linear in

homogeneous coordinates!

TranslationRotation

Rigid / EuclideanLinear

Affine

Projective

Similitudes

Isotropic Scaling

Scaling

Shear

Reflection

Perspective

Identity

Page 93: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 93

Outline• Intro to Transformations • Useful Classes of Transformations • Representing Transformations,

Homogeneous Coordinates • Combining Transformations • Transforming Normals

Page 94: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 94

How are transforms combined?

(0,0)(1,1)

(2,2)

(0,0)

(5,3)

(3,1)Scale(2,2) Translate(3,1)

TS =2 0

0 2

0 0

1 0

0 1

3 1

2 0

0 2

3 1=

Scale then Translate

Use matrix multiplication: p' = T ( S p ) = TS p

Caution: matrix multiplication is NOT commutative!

0 0 1 0 0 1 0 0 1

Page 95: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 95

Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS p

Translate then Scale: p' = S ( T p ) = ST p

(0,0)

(1,1)(4,2)

(3,1)

(8,4)

(6,2)

(0,0)(1,1)

(2,2)

(0,0)

(5,3)

(3,1)Scale(2,2) Translate(3,1)

Translate(3,1) Scale(2,2)

Page 96: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 96

TS =2 0 0

0 2 0

0 0 1

1 0 0

0 1 0

3 1 1

ST =2 0

0 2

0 0

1 0

0 1

3 1

Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS p

2 0 0

0 2 0

3 1 1

2 0

0 2

6 2

=

=

Translate then Scale: p' = S ( T p ) = ST p

0 0 1 0 0 1 0 0 1

Page 97: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 97

Questions?

Page 98: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 98

Outline• Intro to Transformations • Useful Classes of Transformations • Representing Transformations,

Homogeneous Coordinates • Combining Transformations • Transforming Normals

Page 99: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 99

Normal• Surface Normal: unit vector that is locally

perpendicular to the surface

Page 100: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 100

Why is the Normal important?• It's used for shading — makes things look 3D!

object color only Diffuse Shading

Page 101: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 101

Visualization of Surface Normal

± x = Red ± y = Green ± z = Blue

Page 102: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 102

How do we transform normals?

Object Space World Space

nOS

nWS

Page 103: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 103

Transform Normal like Object?• translation? • rotation? • isotropic scale? • scale? • reflection? • shear? • perspective?

Page 104: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 104

Transform Normal like Object?• translation? • rotation? • isotropic scale? • scale? • reflection? • shear? • perspective?

Page 105: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 105

Similitudes

What class of transforms?

TranslationRotation

Rigid / EuclideanLinear

Affine

Projective

Similitudes

Isotropic Scaling

Scaling

Shear

Reflection

Perspective

IdentityTranslation

RotationIsotropic Scaling

IdentityReflection

a.k.a. Orthogonal Transforms

Page 106: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 106

Transformation for shear and scale

Incorrect Normal

Transformation

Correct Normal

Transformation

Page 107: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 107

More Normal Visualizations

Incorrect Normal Transformation Correct Normal Transformation

Page 108: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 108

• Think about transforming the tangent plane to the normal, not the normal vector

So how do we do it right?

Original Incorrect Correct

nOS

Pick any vector vOS in the tangent plane, how is it transformed by matrix M?

vOSvWS

nWS

vWS = M vOS

Page 109: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 109

Transform tangent vector vv is perpendicular to normal n:

nOST vOS = 0

nOST (M-1 M) vOS = 0

nWST = nOS

T (M-1)

(nOST M-1) (M vOS) = 0 (nOS

T M-1) vWS = 0

nWST vWS = 0

vWS is perpendicular to normal nWS:

nWS = (M-1)T nOS

nOS

vWS

nWS

vOS

Dot product

Page 110: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Digression

110

• The previous proof is not quite rigorous; first you’d need to prove that tangents indeed transform with M. – Turns out they do, but we’ll take it on faith here. – If you believe that, then the above formula follows.

nWS = (M-1)T nOS

Page 111: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 111

Comment• So the correct way to transform normals is:

• But why did nWS = M nOS work for similitudes? • Because for similitude / similarity transforms,

(M-1)T =λ M • e.g. for orthonormal basis: M-1 = M T i.e. (M-1)T = M

nWS = (M-1)T nOS Sometimes denoted M-T

Page 112: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen 112

Connections• Not part of class, but cool

– “Covariant”: transformed by the matrix • e.g., tangent

– “Contravariant”: transformed by the inverse transpose • e.g., the normal • a normal is a “co-vector”

• Google “differential geometry” to find out more

Page 113: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

Questions?

113

Page 114: Coordinate Transformations & Homogeneous Coordinates

CS-C3100 Fall 2016 – Lehtinen

That’s All for Today

114

• Further Reading – Projection handout (MyCourses)

• Other Cool Stuff – Algebraic Groups – http://phototour.cs.washington.edu/ – http://phototour.cs.washington.edu/findingpaths/ – Free-form deformation of solid objects – Harmonic coordinates for character articulation