coordinate transformations & homogeneous coordinates

Post on 11-Sep-2021

9 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CS-C3100 Fall 2016 – Lehtinen

Coordinate

Transformations & Homogeneous

Coordinates

CS-C3100 (Introduction to) Computer Graphics Jaakko Lehtinen

Lots of slides from Frédo Durand

CS-C3100 Fall 2016 – Lehtinen 2

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

Homogeneous Coordinates • Combining Transformations • Hardcore: Transforming normals

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Pipeline Recap

3

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

CS-C3100 Fall 2016 – Lehtinen

Modeling/Viewing Pipeline Recap

4

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

Object 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

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

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

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.

CS-C3100 Fall 2016 – Lehtinen

Questions?

9

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

CS-C3100 Fall 2016 – Lehtinen 11

Simple Transformations

?

CS-C3100 Fall 2016 – Lehtinen 12

Simple Transformations

• Can be combined • Are these operations invertible?

Yes, except scale = 0

CS-C3100 Fall 2016 – Lehtinen

Questions?

13

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

CS-C3100 Fall 2016 – Lehtinen 15

Rigid-Body / Euclidean Transforms

• What properties are preserved?

TranslationRotation

Rigid / Euclidean

Identity

CS-C3100 Fall 2016 – Lehtinen 16

Rigid-Body / Euclidean Transforms

• Preserves distances • Preserves angles

TranslationRotation

Rigid / Euclidean

Identity

• 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

CS-C3100 Fall 2016 – Lehtinen 18

Linear Transformations

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic ScalingIdentity

Scaling

Shear

Reflection

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

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

???

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)

CS-C3100 Fall 2016 – Lehtinen 22

Affine Transformations

• What is preserved..?

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic Scaling

Scaling

Shear

ReflectionIdentity

Affine

CS-C3100 Fall 2016 – Lehtinen 23

Affine Transformations

• Preserves parallel lines

TranslationRotation

Rigid / EuclideanLinear

Similitudes

Isotropic Scaling

Scaling

Shear

ReflectionIdentity

Affine

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

• 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

• 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

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

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

CS-C3100 Fall 2016 – Lehtinen

Questions?

29

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

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

CS-C3100 Fall 2016 – Lehtinen 32

Questions?

CS-C3100 Fall 2016 – Lehtinen 33

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

Homogeneous Coordinates • Combining Transformations • Transforming Normals

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”!

CS-C3100 Fall 2016 – Lehtinen 35

How are Linear Transforms Represented?

Linear transformations include rotation, scaling,

reflection, and shear

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

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

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.

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

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

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:

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

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

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

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

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

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.

CS-C3100 Fall 2016 – Lehtinen

“Projective Equivalence” in 1D

48

w=0

w=1

w=2

w=3

w

x (0,0)

(x,w)

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)

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)

• 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

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)

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)

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.

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”.

CS-C3100 Fall 2016 – Lehtinen 56

Questions?

• 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

CS-C3100 Fall 2016 – Lehtinen

What’s Actually Happening?

58

x' = x + c

x x’

c

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..?

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’

CS-C3100 Fall 2016 – Lehtinen 61

w=1

w=2

w=0(0,0)

x' = x + c

x

w

What’s Actually Happening?xx’

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’

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

CS-C3100 Fall 2016 – Lehtinen 64

Questions?

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

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'

θ

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

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?

CS-C3100 Fall 2016 – Lehtinen 69

Questions?

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

⌃⌃⌅?

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.

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.

CS-C3100 Fall 2016 – Lehtinen

The Same for Scaling

73

a p =

⇧⇧⇤

a px

a py

a pz

a

⌃⌃⌅Remember projective

equivalence

CS-C3100 Fall 2016 – Lehtinen

The Same for Scaling

74

• You also leave w fixed.

a p =

⇧⇧⇤

a px

a py

a pz

1

⌃⌃⌅

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!

CS-C3100 Fall 2016 – Lehtinen 76

Questions?

CS-C3100 Fall 2016 – Lehtinen

Why Bother II: Perspective

w = 1

w = 2

77

• This picture gives away almost the whole story.

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

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):

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

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

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!

⇧⇧⇤

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.

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.

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

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.

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.

CS-C3100 Fall 2016 – Lehtinen 88

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/

CS-C3100 Fall 2016 – Lehtinen

Want to Know More?

90

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

CS-C3100 Fall 2016 – Lehtinen 91

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

CS-C3100 Fall 2016 – Lehtinen 93

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

Homogeneous Coordinates • Combining Transformations • Transforming Normals

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

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)

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

CS-C3100 Fall 2016 – Lehtinen 97

Questions?

CS-C3100 Fall 2016 – Lehtinen 98

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

Homogeneous Coordinates • Combining Transformations • Transforming Normals

CS-C3100 Fall 2016 – Lehtinen 99

Normal• Surface Normal: unit vector that is locally

perpendicular to the surface

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

CS-C3100 Fall 2016 – Lehtinen 101

Visualization of Surface Normal

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

CS-C3100 Fall 2016 – Lehtinen 102

How do we transform normals?

Object Space World Space

nOS

nWS

CS-C3100 Fall 2016 – Lehtinen 103

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

CS-C3100 Fall 2016 – Lehtinen 104

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

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

CS-C3100 Fall 2016 – Lehtinen 106

Transformation for shear and scale

Incorrect Normal

Transformation

Correct Normal

Transformation

CS-C3100 Fall 2016 – Lehtinen 107

More Normal Visualizations

Incorrect Normal Transformation Correct Normal Transformation

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

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

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

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

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

CS-C3100 Fall 2016 – Lehtinen

Questions?

113

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

top related