52
CSE 681 Review: Transformations

Review: Transformations

Embed Size (px)

DESCRIPTION

Review: Transformations. Transformations. Modeling transformations build complex models by positioning (transforming) simple components relative to each other Viewing transformations placing virtual camera in the world transformation from world coordinates to camera coordinates - PowerPoint PPT Presentation

Citation preview

Page 1: Review: Transformations

CSE 681

Review:Transformations

Page 2: Review: Transformations

CSE 681

Transformations• Modeling transformations

• build complex models by positioning (transforming) simple components relative to each other

• Viewing transformations

• placing virtual camera in the world

• transformation from world coordinates to camera coordinates

• Perspective projection of 3D coordinates to 2D

• Animation

• vary transformations over time to create motion

Page 3: Review: Transformations

CSE 681

Transformations - Modeling

world

Page 4: Review: Transformations

CSE 681

Transformations - Viewing

WORLD

OBJECTCAMERA

Page 5: Review: Transformations

CSE 681

Modeling Transformations

Transform objects/points Transform coordinate system

Page 6: Review: Transformations

CSE 681

Affine Transformations

Transform P = (x, y, z) to Q = (x’, y’, z’) by M.

Affine transformation:

34333231

24232221

14131211

'

'

'

mzmymxmz

mzmymxmy

mzmymxmx

Page 7: Review: Transformations

CSE 681

Translation

Translation by (tx, ty, tz):

(tx, ty, tz)z

y

x

tzz

tyy

txx

'

'

'

Page 8: Review: Transformations

CSE 681

Scaling

Scaling by (sx, sy, sz):

Uniform v. non-uniform scaling

zsz

ysy

xsx

z

y

x

'

'

'

Page 9: Review: Transformations

CSE 681

Rotation

Rotation counter-clockwise by angle around the z-axis:

x’ = x cos() – y sin()

y’ = x sin() + y cos()

z’ = z

Proof:x = r cos()y = r sin()

x’ = r cos( + ) = r cos() cos() – r sin() sin() = x cos() – y sin()y’ = r sin( + ) = r cos() sin() + r sin() cos() = x sin() + y cos()

xz

y

r

r

Page 10: Review: Transformations

CSE 681

Rotation around x-axis

Rotation counter-clockwise by angle around the x-axis:

x’ = x

y’ = y cos() – z sin()

z’ = y sin() + z cos()

yx

z

Page 11: Review: Transformations

CSE 681

Rotation around y-axis

Rotation counter-clockwise by angle around the y-axis:

y’ = y

z’ = z cos() – x sin()

x’ = z sin() + x cos()

Or

x’ = x cos() + z sin()

y’ = y

z’ = – x sin() + z cos()zy

x

Page 12: Review: Transformations

CSE 681

Matrix Multiplication

Rotation counter-clockwise by angle around the z-axis:x’ = x cos() – y sin() y’ = x sin() + y cos() z’ = z

.

00

00

00

'

'

'

z

y

x

s

s

s

z

y

x

z

y

x

x '

y '

z'

cos() sin() 0

sin() cos() 0

0 0 1

x

y

z

.

x '

y '

z'

?

x

y

z

.

Translation by (tx, ty, tz):

x’ = x + tx

y’ = y + ty

z’ = z + tz

Scaling by (sx, sy, sz):

x’ = sx x

y’ = sy y

z’ = sz z

Page 13: Review: Transformations

CSE 681

Homogeneous Coordinates

Scaling by (sx, sy, sz):

x’ = sx x

y’ = sy y

z’ = sz z

.

11000

100

010

001

1

'

'

'

z

y

x

t

t

t

z

y

x

z

y

x

.

11000

000

000

000

1

'

'

'

z

y

x

s

s

s

z

y

x

z

y

x

Represent P by (x, y, z, 1) and Q by (x’, y’, z’, 1).

(Homogeneous coordinates.)

Translation by (tx, ty, tz):

x’ = x + tx

y’ = y + ty

z’ = z + tz

Page 14: Review: Transformations

CSE 681

Rotation Matrices

Rotation counter-clockwise by angle around the x-axis:x’ = xy’ = y cos() – z sin() z’ = y sin() + z cos()

x '

y '

z'

1

cos() sin() 0 0

sin() cos() 0 0

0 0 1 0

0 0 0 1

x

y

z

1

.

.

11000

0)cos()sin(0

0)sin()cos(0

0001

1

'

'

'

z

y

x

z

y

x

.

11000

0)cos(0)sin(

0010

0)sin(0)cos(

1

'

'

'

z

y

x

z

y

x

Rotation counter-clockwise by angle around the z-axis:x’ = x cos() – y sin() y’ = x sin() + y cos() z’ = z

Rotation counter-clockwise by angle around the y-axis:

x’ = x cos() + z sin()

y’ = y

z’ = – x sin() + z cos()

Page 15: Review: Transformations

CSE 681

Affine Transformation Matrix

Affine transformation:

x’ = m11 x + m12 y + m13 z + m14

y’ = m21 x + m22 y + m23 z + m24

z’ = m31 x + m32 y + m33 z + m34

Transformation Matrix:.

110001

'

'

'

34333231

24232221

14131211

z

y

x

mmmm

mmmm

mmmm

z

y

x

Page 16: Review: Transformations

CSE 681

Shearing

Shear along the x-axis:

x’ = x + hy

y’ = y

z’ = z

xz

y

.

11000

0100

0010

001

1

'

'

'

z

y

xh

z

y

x

Page 17: Review: Transformations

CSE 681

Reflection

Reflection across the x-axis:

x’ = (-1) x

y’ = y

z’ = zxz

y

Reflection is a special case of scaling!

.

11000

0100

0010

0001

1

'

'

'

z

y

x

z

y

x

Page 18: Review: Transformations

CSE 681

Elementary Transformations

• Translation

• Rotation

• Scaling

• Shear

What about inverses?

Page 19: Review: Transformations

CSE 681

Inverse Transformations

Translation

Rotation

Scale

Shear

Page 20: Review: Transformations

CSE 681

Compose Transformations

xz

y• Scale by (2, 1, 1)

• Translate by (20, 5, 0)

• Rotate by 30° counter-clockwise around the z-axis

• Translate by (0, -50, 0)

Page 21: Review: Transformations

CSE 681

Compose Transformation Matrices

xz

y• Scale by (2, 1, 1);

.

11000

0100

0010

0002

z

y

x

1

'

'

'

z

y

xScale

• Translate by (20, 5, 0);

1000

0100

5010

20001Translate

• Rotate by 30° counter-clockwise around the z-axis;

1000

0100

0086.05.0

005.086.0Rotate

• Translate by (0, -50, 0).

1000

0100

50010

0001Translate

Page 22: Review: Transformations

CSE 681

Compose Transformation Matrices

xz

y• Scale by (2, 1, 1);

.

11000

0100

3.44088.00.1

7.1405.072.1

1

'

'

'

z

y

x

z

y

x

• Translate by (20, 5, 0);

• Rotate by 30° counter-clockwise around the z-axis;

• Translate by (0, -50, 0).

Page 23: Review: Transformations

CSE 681

Order Matters!

Transformations are not necessarily commutative!

xz

y

• Translate by (20, 0, 0).

• Rotate by 30.

xz

y

• Rotate by 30.

• Translate by (20, 0, 0).

Page 24: Review: Transformations

CSE 681

Order of Transformation Matrices

Apply transformation matrices from right to left.

• Translate by (20, 0, 0).

• Rotate by 30.

• Rotate by 30.

• Translate by (20, 0, 0)..

11000

0100

0086.05.0

005.086.0

1000

0100

0010

20001

1

'

'

'

z

y

x

z

y

x

.

11000

0100

0010

20001

1000

0100

0086.05.0

005.086.0

1

'

'

'

z

y

x

z

y

x

Page 25: Review: Transformations

CSE 681

• Translation and translation?

• Scaling and scaling?

• Rotation and rotation?

• Translation and scaling?

• Translation and rotation?

• Scaling and rotation?

Which transformations commute?

Page 26: Review: Transformations

CSE 681

Elementary Transformations

Theorem: Every affine transformation can be decomposed into elementary operations.

Elementary transformations:• Translation;• Rotation;• Scaling;• Shear.

Euler’s Theorem: Every rotation around the origin can be decomposed into a rotation around the x-axis followed by a rotation around the y-axis followed by a rotation around the z-axis. (or a single rotation about an arbitrary axis).

Page 27: Review: Transformations

CSE 681

Vectors

Vector V = (Vx, Vy, Vz).

Homogeneous coordinates: (Vx, Vy, Vz, 0).

Affine transformation: .

010000

'

'

'

34333231

24232221

14131211

z

y

x

z

y

x

V

V

V

mmmm

mmmm

mmmm

V

V

V

Page 28: Review: Transformations

CSE 681

Vectors

Rotation:

Scaling:

Translation:(Note: No change.)

.

01000

0100

00)cos()sin(

00)sin()cos(

0

'

'

'

z

y

x

z

y

x

V

V

V

V

V

V

.

01000

100

010

001

0

z

y

x

z

y

x

z

y

x

V

V

V

t

t

t

V

V

V

.

01000

000

000

000

0

'

'

'

z

y

x

z

y

x

z

y

x

V

V

V

s

s

s

V

V

V

Page 29: Review: Transformations

CSE 681

Transform Parametric Line

P0

V

Q0

W

u

u

P(u)

M

Q(u)

MM

Page 30: Review: Transformations

CSE 681

Line

Theorem: Affine transformations transform lines to lines.

transformed point on a line = point on transformed line

TTT VuMPMuVPM ][][][ 00

TT uVPMuPM ][)]([ 0

Page 31: Review: Transformations

CSE 681

Affine Transformation of Lines

xz

y

xz

y

Page 32: Review: Transformations

CSE 681

Affine Combinations

P

Q

P’

Q’

ab

b

a

R

M

R’

MM

Page 33: Review: Transformations

CSE 681

Affine Combinations

Theorem: Affine transformations preserve affine combinations.

TTT bQMaPMbQaPM ][][][

TT bQaPMRM ][][

''][][][][ bQaPPaMPaMbQMaPM TTTT

Page 34: Review: Transformations

CSE 681

Properties of Affine Transformations

• Affine transformations map lines to lines;• Affine transformations preserve affine combinations;• Affine transformations preserve parallelism;• Affine transformations change volume by | Det(M) |;• Any affine transformation can be decomposed into

elementary transformations.• Affine transformations [does/does not] preserve angles?• Affine transformations [does/does not] preserve the

intersection of two lines?• Affine transformations [does/does not] preserve distances?

Page 35: Review: Transformations

CSE 681

Properties of Transformation Matrices

Second column is how (0,1,0,0) transforms

1000

0100

0010

0001

????

????

????

????

44434241

34333231

24232221

14131211

mmmm

mmmm

mmmm

mmmm

0

0

0

1

?

?

?

?

44434241

34333231

24232221

14131211

mmmm

mmmm

mmmm

mmmm

Matrix holds how coordinate axes transform and how origin transforms

Third column is how (0,0,1,0) transforms

First column is how (1,0,0,0) transforms

Page 36: Review: Transformations

CSE 681

Properties of Pure Rotation Matrices

Rows (columns) are orthogonal to each other

A row dot product any other row = 0

Each row (column) dot product times itself = 1

RT = R-1

Page 37: Review: Transformations

CSE 681

Coordinate Frame

• Coordinate frame is given by origin and three mutually orthogonal unit vectors, i, j, k - defined in (x,y,z) space

• Mutually orthogonal (dot products): i•j = ?; i•k = ?; j•k = ?.• Unit vectors (dot products): i•i = ?; j•j = ?; k•k = ?.

xz

y

ij

k

Page 38: Review: Transformations

CSE 681

Orientation

Right handed coordinate system: Left handed coordinate system:

xz

y

(Out of page)

x

z

y

(Into page)

Page 39: Review: Transformations

CSE 681

Orientation

xz

y

ij

k

Right handed coordinate system: Left handed coordinate system:

Cross product: i x j = ?

xz

y

ij

k

Cross product: i x j = ?

How do you test whether (i,j,k) is left handed or right handed?

Page 40: Review: Transformations

CSE 681

Coordinate Transformations

xz

y

ij

k

Given object data points defined in the (i, j, k, ) coordinate frame,Given the definition of (i, j, k, ) in (x, y, z) coordinates,

How do you determine the coordinates of the object data points in the (x, y, z, 0) frame?

Page 41: Review: Transformations

CSE 681

Coordinate change (Translation)

(x, y, z)

.

110001

c

b

a

z

y

x

xz

y

a

c

b

(0,0,0)

Change from (a,b,c,) coordinates to (x,y,z,0) coordinates:

1. Move (a,b,c, ) to (x,y,z,0) and invert2. Move data relative from (0,0,0) out to

position by adding

Page 42: Review: Transformations

CSE 681

Coordinate change (Rotation)

.

110001

c

b

a

z

y

x

c

(x, y, z)

a

b

(0,0,0)

Change from (a,b,c,) coordinates to (x,y,z,0) coordinates:

y x

z

z-axis rotation by

1. Rotate (a,b,c) by and invert 2. Rotate data by -

Page 43: Review: Transformations

CSE 681

Object Transformations

xz

y

Given (i,j,k,p) defined in the (x,y,z,0) coordinate frame, Transform points

defined in the (i, j, k, ) coordinate frame to the (x,y,z,0) coordinate frame.

Rotate object to get x to line up with i, then translate to

ij

k

.

10

z

y

x

1

0

0

0

0

0

1

0

0

1

0

ij

k

.

1000

0

0

0

zzz

yyy

xxx

kji

kji

kji

Page 44: Review: Transformations

CSE 681

Object Transformations

xz

y

ij

k

ij

k

.

1000

zzzz

yyyy

xxxx

kji

kji

kji

Affine transformation matrix:

Page 45: Review: Transformations

CSE 681

Coordinate Transformations

xz

y

ij

k

Given (i,j,k,) defined in the (x,y,z,0) coordinate frame, Transform points in (i,j,k,0) coordinate frame to (x,y,z, ) coordinate frame.

translate by - , then rotate to align i with x – then invert

Page 46: Review: Transformations

CSE 681

Coordinate Transformations

1000

0

0

0

zyx

zyx

zyx

kkk

jjj

iii

xz

y

ij

k

R=

1000

100

010

001

z

y

x

T =

Page 47: Review: Transformations

CSE 681

Coordinate Transformations

xz

y

ij

k

.

1000

zzzz

yyyy

xxxx

kji

kji

kji

Affine transformation matrix:

Apply RT to coordinate systemApply (RT)-1 to data = T-1R-1

Page 48: Review: Transformations

CSE 681

Composition of coordinate change

z”0

x”

y”

M1 changes from coordinate frame (x,y,z,) to (x’,y’,z’,’).

M2 changes from coordinate frame (x’,y’,z’,’) to (x’’,y’’,z’’,’’).

Change from coordinate frame (x,y,z,) to (x’’,y’’,z’’,0): ?

z’

’ x’

y’

z

x

y

M2

M1

2

Page 49: Review: Transformations

CSE 681

Composition of transformations - example

x

y

A

B

B’

Page 50: Review: Transformations

CSE 681

Transformations of normal vectors

n is a unit normal vector to plane .

M is an affine transformation matrix.

How is n transformed, to keep it perpendicular to the plane, under:

• translation?

• rotation by ?

• uniform scaling by s?

• shearing or non-uniform scaling?

n

Page 51: Review: Transformations

CSE 681

Non-uniform scale transformation

n is a unit normal vector to plane : (-nx,0)

M is a non-uniform scale transformation matrix that only modifies x-coordinates

If we just transform the n as a vector, then M nT = n’

But we want n’’ – that has a non-zero y-coordinate value

n n’ n

Page 52: Review: Transformations

CSE 681

Transformations of normal vectorsPlanar equation: a x + b y + c z + d = 0.Let N = (a, b, c, d). (Note: (a, b, c) is normal vector)Let P = (x, y, z, 1) be a point in plane .Planar equation: N • P = 0.M is an affine transformation matrix. (MT is M transpose.)Let P’ = M PT.Find N’ such that N’ • P’ = 0 (transformed planar equation)N • P = 0;N PT = 0;N (M-1 M) PT = 0;(N M-1) (M PT) = 0;(N M-1) P’T = 0;So N’ = NM-1

To put in column-vector form, (N’)T = (NM-1)T = (M-1)TNT

So N’ = ((M-1)T NT)T and (M-1)T is the transformation matrix to take NT into N’T Note: If M is a rotation matrix, (M-1)T = M.

n P