Lecture 8: Coordinate Frame Transformations

38
Magnitude of a Vector โ€ข Magnitude of a โ€“ If a =(2, 5, 6) โ€ข Normalizing a vector 1

Transcript of Lecture 8: Coordinate Frame Transformations

Page 1: Lecture 8: Coordinate Frame Transformations

Magnitude of a Vector

โ€ข Magnitude of a

โ€“ If a =(2, 5, 6)

โ€ข Normalizing a vector

1

Page 2: Lecture 8: Coordinate Frame Transformations

CITS3003 Graphics & Animation

Lecture 8:

Coordinate Frame

Transformations

Page 3: Lecture 8: Coordinate Frame Transformations

Breakdown of Lectures

1. Introduction & Image Formation

2. Programming with OpenGL

3. OpenGL: Pipeline Architecture

4. OpenGL: An Example Program

5. Vertex and Fragment Shaders 1

6. Vertex and Fragment Shaders 2

7. Representation and Coordinate Systems

8. Coordinate Frame Transformations

9. Transformations and Homogeneous Coordinates

10. Input, Interaction and Callbacks

11. Mid-semester Test

12. More on Callbacks

13. 3D Hidden Surface Removal

13. Computer Viewing

- Study break

15. Programming Project Discussion

16. Shading

17. Shading Models

18. Shading in OpenGL

19. Texture Mapping

20. Texture Mapping in OpenGL

21. Hierarchical Modelling

22. 3D Modelling: Subdivision Surfaces

23. Animation Fundamentals and Quaternions

24. Skinning

3

Page 4: Lecture 8: Coordinate Frame Transformations

Content

โ€ข Learn how to define and change coordinate

frames

โ€ข Derive homogeneous coordinate

transformation matrices

โ€ข Introduce standard transformations

โ€“ Rotation, Translation, Scaling, Shear

4

Page 5: Lecture 8: Coordinate Frame Transformations

Coordinate Frame

โ€ข Basis vectors alone cannot represent points

โ€ข We can add a single point, the origin, to the

basis vectors to form a coordinate frame

P0v1

v2

v3

5

Page 6: Lecture 8: Coordinate Frame Transformations

Representation in a Coordinate Frame

โ€ข A coordinate system (or coordinate frame) is

determined by ๐0, ๐ฏ1, ๐ฏ2, ๐ฏ3โ€ข Within this coordinate frame, every vector v

can be written as

v = ฮฑ1v1+ ฮฑ2v2 + ฮฑ3v3

Every point can be written as

P = P0 + ฮฒ1v1+ ฮฒ2v2 + ฮฒ3v3

for some ๐›ผ1, ๐›ผ2, ๐›ผ3, and ๐›ฝ1, ๐›ฝ2, ๐›ฝ3

6

Page 7: Lecture 8: Coordinate Frame Transformations

Homogeneous Coordinates

โ€ข Consider the point P and the vector v, where

P = P0 + ฮฒ1v1+ ฮฒ2v2 + ฮฒ3v3

v = ฮฑ1v1+ ฮฑ2v2 + ฮฑ3v3

โ€ข They appear to have similar representations:

P = [ฮฒ1, ฮฒ2, ฮฒ3]T , v =[ฮฑ1, ฮฑ2, ฮฑ3]T which

confuses the point with the vector

A vector has no position v

P

v

Vector can be placed anywhere

point: fixed

7

Page 8: Lecture 8: Coordinate Frame Transformations

A Single Representation

โ€ข Assuming 0 โˆ™ ๐ = ๐ŸŽ and 1 โˆ™ ๐ = ๐ , we can write

๐ฏ = ๐›ผ1๐ฏ1 + ๐›ผ2๐ฏ2 + ๐›ผ3๐ฏ3 = ๐›ผ1๐ฏ1 + ๐›ผ2๐ฏ2 + ๐›ผ3๐ฏ3 + 0 โˆ™ ๐0๐ = ๐›ฝ1๐ฏ1 + ๐›ฝ2๐ฏ2 + ๐›ฝ3๐ฏ3 + ๐0 = ๐›ฝ1๐ฏ1 + ๐›ฝ2๐ฏ2 + ๐›ฝ3๐ฏ3 + 1 โˆ™ ๐0

โ€ข Thus, we obtain the four-dimensional homogeneous

coordinate representation

๐ฏ = ๐›ผ1 ๐›ผ2 ๐›ผ3 0 ๐‘‡

๐ = ๐›ฝ1 ๐›ฝ2 ๐›ฝ3 1 ๐‘‡

8

Page 9: Lecture 8: Coordinate Frame Transformations

Homogeneous Coordinates

โ€ข The homogeneous coordinate form for a three-dimensional point ๐‘ฅ ๐‘ฆ ๐‘ง T is given as

๐ฉ = ๐‘ฅ ๐‘ฆ ๐‘ง 1 T ๐‘ค๐‘ฅ ๐‘ค๐‘ฆ ๐‘ค๐‘ง ๐‘ค T = ๐‘ฅโ€ฒ ๐‘ฆโ€ฒ ๐‘งโ€ฒ ๐‘ค T

โ€ข We return to a three-dimensional point (for ๐‘ค โ‰  0) by๐‘ฅ โ† ๐‘ฅโ€ฒ/๐‘ค๐‘ฆ โ† ๐‘ฆโ€ฒ/๐‘ค๐‘ง โ† ๐‘งโ€ฒ/๐‘ค

โ€ข If ๐‘ค = 0, the representation is that of a vector

โ€ข Homogeneous coordinates replace points in three dimensions by lines through the origin in four dimensions

โ€ข For ๐‘ค = 1, the representation of a point is ๐‘ฅ ๐‘ฆ ๐‘ง 1 T

9

Page 10: Lecture 8: Coordinate Frame Transformations

โ€ข Homogeneous coordinates are key to all

computer graphics systemsโ€“ All standard transformations (rotation, translation, scaling)

can be implemented with matrix multiplications using 4 x 4

matrices

โ€“ Hardware pipeline works with 4 dimensional representations

โ€“ For orthographic viewing, we can maintain w = 0 for

vectors and w = 1 for points

โ€“ For perspective we need a perspective division

10

Homogeneous Coordinates and Computer Graphics

Page 11: Lecture 8: Coordinate Frame Transformations

Representing the Second Basis in

Terms of the First

โ€ข How can we relate ๐ฎ with ๐ฏ?

โ€ข Each of the basis vectors ๐ฎ1, ๐ฎ2, and ๐ฎ3 are vectors that

can be represented in terms of the first set of basis

vectors,

i.e.,

for some ๐›พ11, โ€ฆ , ๐›พ33

๐ฐ๐ฎ1 = ๐›พ11๐ฏ1 + ๐›พ12๐ฏ2+๐›พ13๐ฏ3๐ฎ2 = ๐›พ21๐ฏ1 + ๐›พ22๐ฏ2+๐›พ23๐ฏ3๐ฎ3 = ๐›พ31๐ฏ1 + ๐›พ32๐ฏ2+๐›พ33๐ฏ3

11

Page 12: Lecture 8: Coordinate Frame Transformations

Representing the Second Basis in

Terms of the First (cont.)โ€ข ๐ฎ1 = ๐›พ11๐ฏ1 + ๐›พ12๐ฏ2+๐›พ13๐ฏ3 can be written as:

๐ฎ1 = ๐ฏ1 ๐ฏ2 ๐ฏ3

๐›พ11๐›พ12๐›พ13

= ๐•

๐›พ11๐›พ12๐›พ13

โ€ข Similarly, ๐ฎ2 = ๐›พ21๐ฏ1 + ๐›พ22๐ฏ2+๐›พ23๐ฏ3 and ๐ฎ3 = ๐›พ31๐ฏ1 + ๐›พ32๐ฏ2+๐›พ33๐ฏ3 can be written as:

๐ฎ2 = ๐•

๐›พ21๐›พ22๐›พ23

๐ฎ3 = ๐•

๐›พ31๐›พ32๐›พ33

12

Page 13: Lecture 8: Coordinate Frame Transformations

Representing the Second Basis in

Terms of the First (cont.)

โ€ข We can put the terms ๐›พ11, โ€ฆ , ๐›พ33 into a 3 ร— 3 matrix:

๐Œ =

๐›พ11 ๐›พ12 ๐›พ13๐›พ21 ๐›พ22 ๐›พ23๐›พ31 ๐›พ32 ๐›พ33

then we have:๐ฎ1 ๐ฎ2 ๐ฎ3 = ๐•๐ŒT

That is,

๐” = ๐•๐ŒT

The superscript T denotes

matrix transpose

13

Page 14: Lecture 8: Coordinate Frame Transformations

The same vector w represented in two

coordinate systemsโ€ข We can write

๐ฐ = ๐›ผ1๐ฏ1 + ๐›ผ2๐ฏ2 + ๐›ผ3๐ฏ3๐ฐ = ๐›ฝ1๐ฎ1 + ๐›ฝ2๐ฎ2 + ๐›ฝ3๐ฎ3

as follows:

๐ฐ = ๐ฏ1 ๐ฏ2 ๐ฏ3

๐›ผ1๐›ผ2๐›ผ3

= ๐• ๐š

๐ฐ = ๐ฎ1 ๐ฎ2 ๐ฎ3

๐›ฝ1๐›ฝ2๐›ฝ3

= ๐” ๐›Each ๐ฏ๐‘– is a

column

vector of 3

components

Letโ€™s call this

3 ร— 3 matrix ๐•

14

Page 15: Lecture 8: Coordinate Frame Transformations

Representing the Second Basis in

Terms of the First (cont.)

โ€ข In this example, we have ๐ฐ = ๐• ๐š and ๐ฐ = ๐” ๐›.

โ€ข So

๐• ๐š = ๐” ๐›

โ€ข With ๐” = ๐•๐ŒT, we have

๐• ๐š = ๐•๐ŒT๐›โ‡’ ๐š = ๐ŒT๐›

โ€ข Thus, ๐š and ๐› are related by ๐ŒT

15

Page 16: Lecture 8: Coordinate Frame Transformations

Representing the Second Basis in

Terms of the First (cont.)

โ€ข In this example, we have ๐ฐ = ๐• ๐š and ๐ฐ = ๐” ๐›.

โ€ข So

๐• ๐š = ๐” ๐›

โ€ข With ๐” = ๐•๐ŒT, we have

๐• ๐š = ๐•๐ŒT๐›โ‡’ ๐š = ๐ŒT๐›

โ€ข Thus, ๐š and ๐› are related by ๐ŒT

16Representation w.r.t first basis (V)

Representation w.r.t the second basis (U)

or

Page 17: Lecture 8: Coordinate Frame Transformations

Change of Coordinate Frames

โ€ข We can apply a similar process in homogeneous coordinates

to the representations of both points and vectors

โ€ข Any point or vector can be represented in either coordinate frame.

โ€ข We can represent (Q0, u1, u2, u3) in terms of (P0, v1, v2, v3)

Consider two coordinate

frames:

(P0, v1, v2, v3)

(Q0, u1, u2, u3)

P0 v1

v2

v3

Q0

u1u2

u3

17

Page 18: Lecture 8: Coordinate Frame Transformations

Representing One Coordinate Frame in

Terms of the Other

โ€ข We can extend what we did with the change of basis

vectors:

by replacing the 3 ร— 3 matrix ๐Œ by a 4 ร— 4 matrix as follows:

๐ฎ1 = ๐›พ11๐ฏ1 + ๐›พ12๐ฏ2+๐›พ13๐ฏ3๐ฎ2 = ๐›พ21๐ฏ1 + ๐›พ22๐ฏ2+๐›พ23๐ฏ3๐ฎ3 = ๐›พ31๐ฏ1 + ๐›พ32๐ฏ2+๐›พ33๐ฏ3๐0 = ๐›พ41๐ฏ1 + ๐›พ42๐ฏ2+๐›พ43๐ฏ3 + ๐0

๐Œ =

๐›พ11 ๐›พ12 ๐›พ13๐›พ21 ๐›พ22 ๐›พ23๐›พ31 ๐›พ32 ๐›พ33

000

๐›พ41 ๐›พ42 ๐›พ43 1

18

Page 19: Lecture 8: Coordinate Frame Transformations

Working with Representations

โ€ข Within the two coordinate frames any point or vector has a representation of the same form:

๐š = ๐›ผ1 ๐›ผ2 ๐›ผ3 ๐›ผ4 in the first frame

๐› = ๐›ฝ1 ๐›ฝ2 ๐›ฝ3 ๐›ฝ4 in the second frame

where a4 = b4 = 1 for points and a4 = b4 = 0 for vectors and

๐š = ๐ŒT๐›

โ€ข The matrix ๐ŒT is 4 ร— 4 and specifies an affine transformation in homogeneous coordinates

19

or

Page 20: Lecture 8: Coordinate Frame Transformations

Transformations in Graphics pipeline

1. Object (or model) coordinates

2. World coordinates

3. Eye (or camera) coordinates

4. Clip coordinates

5. Normalized device coordinates

6. Window (or screen) coordinates

The six frames are w.r.t. immediate-mode rendering

We had considered the following coordinate systems

Affine

transform

Can be

combined in

model-view

transform

Brings representations

in the eye-frame

Page 21: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

01

Camera and object frame in default positions

model-view matrix

Page 22: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

Where did we get A

(model-view matrix) from?

Page 23: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

Remember?

Page 24: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

Remember?

Refer to

slide#18

Page 25: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

Remember?

Representation

w.r.t camera

frame

Representation

w.r.t object

frame

Page 26: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

Remember?

Representation

w.r.t camera

frame

Representation

w.r.t object

frame

Page 27: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

Remember?

Representation

w.r.t camera

frame

Representation

w.r.t object

frame

Model View

matrix (A)

Page 28: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

This matrix takes a point (0, 0, d) in the

object/world frame, whose representation is:

p =[0 0 ๐‘‘ 1]๐‘‡

to

pโ€™= [0 0 0 1]๐‘‡

i.e., the origin in the camera frame

Page 29: Lecture 8: Coordinate Frame Transformations

Moving the Camera

๐€ =

1 0 0 00 1 0 000

00

10

โˆ’๐‘‘1

โ€ข The application programmer works in the object/world coordinates (a.k.a. application frame)

Camera frame is fixed, we are placing object frame relative to

the camera frame.

This matrix takes a point (0, 0, d) in the

object/world frame, whose representation is:

p=[0 0 ๐‘‘ 1]๐‘‡

to

pโ€™= [0 0 0 1]๐‘‡

i.e., the origin in the camera frame

๐ฉโ€ฒ = ๐€๐ฉ

Page 30: Lecture 8: Coordinate Frame Transformations

The World and Camera Coordinate

Framesโ€ข When we work with representations, we work with

n-tuples or arrays of scalars

โ€ข Changes in coordinate frame are then defined by 4 ร— 4matrices

โ€ข In OpenGL, the base frame that we start with is the world frame

โ€ข Eventually we represent entities in the camera frame by changing the world representation using the model-view matrix

โ€ข Initially these frames are the same (i.e., M=I)

30

Page 31: Lecture 8: Coordinate Frame Transformations

An Example

We consider two reference frames that have basis vector relation

Let's say the reference point does not change, so

Our matrix MT would be:

Only accounting for

rotation

Page 32: Lecture 8: Coordinate Frame Transformations

An Example

Now, we want our frames to have different reference pointโ€ฆ.

Letโ€™s say, to the point Q0 that has the following representation in

the original system.

The MT for such a setting will be:

Also accounting for

translation

Page 33: Lecture 8: Coordinate Frame Transformations

A Few Common Transformations

โ€ข Rigid transformation: The 4 ร— 4 matrix has the form:

๐‘… ๐ญ๐ŸŽT 1

where ๐‘… is a 3 ร— 3 rotation matrix and ๐ญ โˆˆ โ„๐Ÿ‘๐ฑ๐Ÿ is a

translation vector. Rigid transformation preserves

everything (angle (this means the shape), length, area, etc.,)

โ€ข Similarity transformation: The matrix has the form:

๐‘ ๐‘… ๐ญ๐ŸŽT 1

or๐‘… ๐ญ๐ŸŽT ๐‘ โ€ฒ

where ๐‘ , ๐‘ โ€ฒ โ‰  1. Similarity transformation preserves angle,

ratios of lengths and of areas.

Large (or small) ๐‘ values enlarge (or

diminish) the object

Small (or large) ๐‘ โ€ฒvalues enlarge (or

diminish) the object

33

Page 34: Lecture 8: Coordinate Frame Transformations

A Few Common Transformations (cont.)

โ€ข Affine transformation: The 4 ร— 4 matrix has the form:

๐ด ๐ญ๐ŸŽT 1

where ๐ด can be any 3 ร— 3 non-singular matrix and

๐ญ โˆˆ โ„๐Ÿ‘ is a translation vector. Affine transformation

preserves parallelism, ratios of lengths.

โ€ข Perspective transformation: The matrix can be any non-

singular 4 ร— 4 matrix. Perspective transformation matrix

preserves cross ratios (i.e., ratio of ratios of lengths).

34

Page 35: Lecture 8: Coordinate Frame Transformations

โ€ข Rigid transformation is equivalent to a change in

coordinate frames. It has 6 degrees of freedom (dof) i.e.,

3 rotations + 3 translations (along each of the three axes)

โ€ข Similarity transformation has 7 dof (an additional scaling)

โ€ข Affine transformation has 12 dofโ€“ 3 rotations + 3 translations + 3 scaling + 3 shear

35

A Few Common Transformations (cont.)

Page 36: Lecture 8: Coordinate Frame Transformations

General Transformations

โ€ข A transformation maps points to other points

and/or vectors to other vectors

Q=T(P)

v = T(u)

36

Page 37: Lecture 8: Coordinate Frame Transformations

Pipeline Implementation

v

transformation rasterizer

u

u

v

T

T(u)

T(v)

T(u)

T(v)

vertices(before transformation)

vertices(after transformation)

pixels

frame

buffer

(from application program)

T(u)

T(v)

37

Page 38: Lecture 8: Coordinate Frame Transformations

Further Reading

โ€œInteractive Computer Graphics โ€“ A Top-Down Approach with Shader-Based OpenGLโ€ by Edward Angel and Dave Shreiner, 6th

Ed, 2012

โ€ข Sec 3.7 to 3.9