CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex...

Post on 30-Dec-2015

218 views 0 download

Tags:

Transcript of CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex...

CSE 681

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

CSE 681

Transformations - Modeling

world

CSE 681

Transformations - Viewing

WORLD

OBJECTCAMERA

CSE 681

Modeling Transformations

Transform objects/points Transform coordinate system

CSE 681

Affine Transformations

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

Affine transformation:

34333231

24232221

14131211

'

'

'

mzmymxmz

mzmymxmy

mzmymxmx

CSE 681

Translation

Translation by (tx, ty, tz):

(tx, ty, tz)z

y

x

tzz

tyy

txx

'

'

'

CSE 681

Scaling

Scaling by (sx, sy, sz):

Uniform v. non-uniform scaling

zsz

ysy

xsx

z

y

x

'

'

'

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

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

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

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

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

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

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

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

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

CSE 681

Elementary Transformations

• Translation

• Rotation

• Scaling

• Shear

What about inverses?

CSE 681

Inverse Transformations

Translation

Rotation

Scale

Shear

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)

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

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

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

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

CSE 681

• Translation and translation?

• Scaling and scaling?

• Rotation and rotation?

• Translation and scaling?

• Translation and rotation?

• Scaling and rotation?

Which transformations commute?

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

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

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

CSE 681

Transform Parametric Line

P0

V

Q0

W

u

u

P(u)

M

Q(u)

MM

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

CSE 681

Affine Transformation of Lines

xz

y

xz

y

CSE 681

Affine Combinations

P

Q

P’

Q’

ab

b

a

R

M

R’

MM

CSE 681

Affine Combinations

Theorem: Affine transformations preserve affine combinations.

TTT bQMaPMbQaPM ][][][

TT bQaPMRM ][][

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

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?

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

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

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

CSE 681

Orientation

Right handed coordinate system: Left handed coordinate system:

xz

y

(Out of page)

x

z

y

(Into page)

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?

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?

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

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 -

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

CSE 681

Object Transformations

xz

y

ij

k

ij

k

.

1000

zzzz

yyyy

xxxx

kji

kji

kji

Affine transformation matrix:

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

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 =

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

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

CSE 681

Composition of transformations - example

x

y

A

B

B’

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

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

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