Top Banner
CSE 167: Introduction to Computer Graphics Introduction to Computer Graphics Lecture #2: Coordinate Transformations Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011
52

CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Mar 31, 2018

Download

Documents

nguyentuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

CSE 167:

Introduction to Computer GraphicsIntroduction to Computer Graphics

Lecture #2: Coordinate Transformations

Jürgen P. Schulze, Ph.D.

University of California, San Diego

Fall Quarter 2011

Page 2: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Announcements

� Homework #1 due Friday Sept 30, 1:30pm; presentation in lab 260

� Don’t save anything on the C: drive of the lab PCs in Windows. You will lose it when you log out!

2

Page 3: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Overview

� Linear Transformations

� Homogeneous Coordinates

� Affine Transformations

� Concatenating Transformations

� Change of Coordinates� Change of Coordinates

� Common Coordinate Systems

3

Page 4: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Linear Transformations

� Scaling, shearing, rotation, reflection of vectors, and combinations thereof

� Implemented using matrix multiplications

4

Page 5: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Scaling

� Uniform scaling matrix in 2D

� Analogous in 3D

5

Page 6: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Scaling

� Nonuniform scaling matrix in 2D

� Analogous in 3D

6

Page 7: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Shearing

� Shearing along x-axis in 2D

� Analogous for y-axis, in 3D

7

Page 8: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotation in 2D

� Convention: positive angle rotates counterclockwise

� Rotation matrix

8

Page 9: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotation in 3D

Rotation around coordinate axes

9

Page 10: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotation in 3D

� Concatenation of rotations around x, y, z axes

� are called Euler angles

� Result depends on matrix order!� Result depends on matrix order!

10

Page 11: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotation in 3D

Around arbitrary axis

� Rotation axis a

R(a,θ ) =

1+ (1 − cos(θ ))(ax

2− 1) −a

zsin(θ ) + (1− cos(θ))a

xa

ya

ysin(θ) + (1 − cos(θ ))a

xa

z

azsin(θ ) + (1− cos(θ ))a

ya

x1+ (1− cos(θ))(a

y

2− 1) −a

xsin(θ) + (1 − cos(θ))a

ya

z

−aysin(θ) + (1− cos(θ ))a

za

xa

xsin(θ ) + (1− cos(θ ))a

za

y1+ (1− cos(θ))(a

z

2− 1)

� Rotation axis a

� a must be a unit vector:

� Right-hand rule applies for direction of rotation

� Counterclockwise rotation

a = 1

11

Page 12: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Overview

� Linear Transformations

� Homogeneous Coordinates

� Affine Transformations

� Concatenating Transformations

� Change of Coordinates� Change of Coordinates

� Common Coordinate Systems

12

Page 13: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Homogeneous Coordinates

� Generalization: homogeneous point

� Homogeneous coordinate

Corresponding 3D point: divide by homogeneous � Corresponding 3D point: divide by homogeneous coordinate

13

Page 14: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Homogeneous coordinates

� Usually for 3D points you choose

� For 3D vectors

� Benefit: same representation for vectors and points

14

Page 15: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Translation

Using homogeneous coordinates

15

Page 16: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Translation

Using homogeneous coordinates

Matrix notationMatrix notation

Translation matrix

16

Page 17: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Transformations

� Add 4th row/column to 3 x 3 transformation matrices

� Example: rotation

17

Page 18: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Transformations

Concatenation of transformations:

� Arbitrary transformations (scale, shear, rotation, translation)

� Build “chains” of transformations

� Result depends on order� Result depends on order

18

Page 19: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Overview

� Linear Transformations

� Homogeneous Coordinates

� Affine Transformations

� Concatenating Transformations

� Change of Coordinates� Change of Coordinates

� Common Coordinate Systems

19

Page 20: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Affine transformations

� Generalization of linear transformations

� Scale, shear, rotation, reflection (linear)

� Translation

� Preserve straight lines, parallel lines

� Implementation using 4x4 matrices and homogeneous Implementation using 4x4 matrices and homogeneous coordinates

20

Page 21: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Translation

21

Page 22: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Translation

• Inverse translation

22

Page 23: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Scaling

• Origin does not change

23

Page 24: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Scaling

� Inverse of scale:

24

Page 25: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Shear

� Pure shear if only one parameter is non-zero

25

Page 26: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotation around coordinate axis

� Origin does not change

26

Page 27: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotation around arbitrary axis

� Origin does not change

� Angle , unit axis a

27

Page 28: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotation matrices

� Orthonormal

� Rows, columns are unit length and orthogonal

� Inverse of rotation matrix:

� Its transpose

28

Page 29: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Overview

� Linear Transformations

� Homogeneous Coordinates

� Affine Transformations

� Concatenating Transformations

� Change of Coordinates� Change of Coordinates

� Common Coordinate Systems

29

Page 30: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotating with pivot

Rotation around

originRotation with

pivot

30

Page 31: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Rotating with pivot

1. Translation 2. Rotation 3. Translation

31

Page 32: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Concatenating transformations

� Arbitrary sequence of transformations

� Note: associativity

32

Page 33: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Overview

� Linear Transformations

� Homogeneous Coordinates

� Affine Transformations

� Concatenating Transformations

� Change of Coordinates� Change of Coordinates

� Common Coordinate Systems

33

Page 34: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Change of coordinates

� Point with homogeneous coordinates

� Position in 3D given with respect to a coordinate system

34

Page 35: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Change of coordinates

New uvwq

coordinate system

Goal: Find coordinates of with respect to

new uvwq coordinate system35

Page 36: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Change of coordinates

Coordinates of xyzo frame w.r.t. uvwq frame

36

Page 37: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Change of coordinates

Same point p in 3D, expressed in new uvwq frame

37

Page 38: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Change of coordinates

38

Page 39: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Change of coordinates

Inverse transformation

� Given point w.r.t. frame

� Coordinates w.r.t. frame

39

Page 40: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Overview

� Linear Transformations

� Homogeneous Coordinates

� Affine Transformations

� Concatenating Transformations

� Change of Coordinates� Change of Coordinates

� Typical Coordinate Systems

40

Page 41: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Typical Coordinate Systems

� Camera, world, object coordinates:

World coordinates

Object

coordinates

Camera

coordinates

Page 42: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Object Coordinates

� Coordinates the object is defined with

� Often origin is in middle, base, or corner of object

� No right answer, whatever was convenient for the creator of the object

World coordinates

Object

coordinates

Camera

coordinates

42

Page 43: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

World Coordinates

� “World space”

� Common reference frame for all objects in the scene

� Chosen for convenience, no right answer

� If there is a ground plane, usually x/y is horizontal and z points up (height)

� In OpenGL x/y is screen plane, z comes out

World coordinates

Object

coordinates

Camera

coordinates

43

Page 44: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

World Coordinates

� Transformation from object to world space is different for each object

� Defines placement of object in scene

� Given by “model matrix” (model-to-world transform) M

World coordinates

Object

coordinates

Camera

coordinates

44

Page 45: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Camera Coordinate System

� “Camera space”

� Origin defines center of projection of camera

� x-y plane is parallel to image plane

� z-axis is perpendicular to image plane

World coordinates

Object

coordinates

Camera

coordinates

45

Page 46: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Camera Coordinate System

� The Camera Matrix defines the transformation from camera to world coordinates

� Placement of camera in world

� Transformation from object to camera coordinates

World coordinates

Object

coordinates

Camera

coordinates

46

Page 47: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Camera Matrix

� Construct from center of projection e, look at d, up-vector up:

World coordinates

Camera

coordinates

47

Page 48: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Camera Matrix

� Construct from center of projection e, look at d, up-vector up:

World coordinates

Camera

coordinates

48

Page 49: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Camera Matrix

� z-axis

� x-axis

� y-axis

49

Page 50: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Inverse of Camera Matrix

� How to calculate the inverse of the camera matrix C-1?

� Generic matrix inversion is complex and compute-intensive

� Observation:

� camera matrix consists of rotation and translation: R x Tcamera matrix consists of rotation and translation: R x T

� Inverse of rotation: R-1 = RT

� Inverse of translation: T(t)-1 = T(-t)

� Inverse of camera matrix: C-1 = T-1 x R-1

50

Page 51: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Objects in Camera Coordinates

� We have things lined up the way we like them on screen

� x to the right

� y up

� -z going into the screen

� Objects to look at are in front of us, i.e. have negative z values

But objects are still in 3D� But objects are still in 3D

� Next step: project scene into 2D

51

Page 52: CSE 167: Introduction to Computer Graphics …ivl.calit2.net/wiki/images/6/60/02_Transformations.pdfIntroduction to Computer Graphics Lecture #2: Coordinate Transformations JürgenP.

Next Lecture

� Rendering Pipeline

� Perspective Projection

52