of 12

• date post

25-May-2018
• Category

## Documents

• view

217

1

Embed Size (px)

### Transcript of Computer Graphics cs314/Vsep2004/lec_pdf/2004-09-21Computer Graphics Copyright 2004, A ......

• 1

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Chapter 3

Transformations

transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Geometric Transformations

Transformation is one-to-oneand onto mapping of nD to itselfAffine transformation (V) = AV+b

A matrixb scalar

In CG Geometric Transformations are affine transformations with geometric meaningNote: transformation has meaning only for vectors for point P (P) is transformation of vector from (0,0) to P

University ofUniversity ofBritish ColumbiaBritish Columbia

Transformations

Transforming an object = transforming all its points

Transforming a polygon = transforming its vertices

Why?

• 2

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Applications

Viewing

Modeling

Articulation

University ofUniversity ofBritish ColumbiaBritish Columbia

Scaling

V = (vx,vy) vector in XY plane

Scaling operator S with parameters (sx,sy):S(sx,sy)(V) = (vxsx, vysy)

University ofUniversity ofBritish ColumbiaBritish Columbia

Scaling

Matrix form:

Independent in x and y

S(sx,sy)(V) = (vx, vy)sx 00 sy

= (vxsx, vysy)

• 3

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Rotation

Polar form:

Rotating V counterclockwise by to W:

)cossinsincos,sinsincoscos(

))sin(),cos((

),(

rrrr

rrywxwW

+=

++=

=

WyV

x

r

V = (vx, vy) = (rcos, r sin)

University ofUniversity ofBritish ColumbiaBritish Columbia

Rotation

Matrix form:

Rotation operator R with parameter at the origin:

=

cossinsincos

R

W r r

V

=

=

( cos , sin )cos sinsin cos

cos sinsin cos

University ofUniversity ofBritish ColumbiaBritish Columbia

Rotation Properties

R is orthogonal

R- - rotation by - is

( ) ( )TRR =1

( ) 1cossinsincos

),()( =

=

RvvVR yx

• 4

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Translation

Translation operator T with parameters (tx,ty):

T(tx,ty)(V) = (vx+ tx, vy+ ty)

University ofUniversity ofBritish ColumbiaBritish Columbia

To represent T in matrix form introduce homogeneous coordinates:

Conversion (projection) from homogeneous space to Euclidean:

In homogeneous coordinates:

Translation - Homogeneous Coordinates

(2,2,1)=(4,4,2)=(1,1,0.5)

V v v v v vhxh

yh

wh

x y= =( , , ) ( , , )1

V v vvv

vvx y

xh

wh

yh

wh= =

( , ) ,

University ofUniversity ofBritish ColumbiaBritish Columbia

Translation

Using homogeneous coordinates, translationoperator may be expressed as:

( , ) ( ) ( , , )

( , , )

t t hx y

x y

x x y y

x yT V v vt t

v t v t

=

= + +

11 0 00 1 0

1

1

• 5

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Transformation Composition

What operation rotates XY by around P = (px,py) ?Answer:

Translate P to originRotate around origin by Translate back

University ofUniversity ofBritish ColumbiaBritish Columbia

Transformation Composition

T R T

p p p p

p p p p

x y x y

x y x y( , ) ( , )

cos sin-sin cos

=

1 0 00 1 0

1

00

0 0 1

1 0 00 1 0

1

University ofUniversity ofBritish ColumbiaBritish Columbia

Transformations Quiz

What do these transformations do?

And these homogeneous ones?

How to mirror through arbitrary line in XY?

What transformation achieves this?

101

1101

1001

1001

1001

a

5.000010001

1-00010001

• 6

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Rotate by Shear

Shear

Rotation by composition of 3 shears

.1

1

101

11

101

101

101

cossin-sincos

++++

=

+=

=

yzyxxyzzxy

zy

xxy

zy

x

0 2

101

,10

1,

1011

,1101

aa

University ofUniversity ofBritish ColumbiaBritish Columbia

Rotate by Shear (cont.)

Solve for x, y,z :

Result

cos =1+xy= yz+1, sin =y= z+xyz+x

y = sin,x = z = tan2

University ofUniversity ofBritish ColumbiaBritish Columbia

What does composition of following two scaled shears do?

Why use it?Is it convenient?What happens when ?

Rotate by Shear (cont.)

10

01

sincos

sectan

cos sinsin cos

=

2

• 7

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Rotation Approximation

For small angles can approximate:

as(Taylor expansion of sin/cos)

Example:

y0=x sin +y cos 'x+yx0=x cos y sin 'xy

cos 1, sin 0

25 10 2 0.5

University ofUniversity ofBritish ColumbiaBritish Columbia

Rotation Approximation

App. rotation matrix

Matrix has to be orthogonal & normalizedAR is orthogonalAR not normalizedNormalize

AR = c1

c

c

c1

!, c = (1+ 2)

p

AR =1 1

University ofUniversity ofBritish ColumbiaBritish Columbia

3D Transformations

All 2D transformations extend to 3D In homogeneous coordinates:

=

=

=

1000010000cossin00sincos

1010000100001

1000000000000

axis z thearoundRotation n Translatio Scaling

),,(),,(

z

zyx

ttt

z

y

x

sss R

ttt

Ts

ss

S zyxzyx

transformations

• 8

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

3D Transformations

Questions:Is S1S2 = S2S1?

Is T1T2 = T2T1?

Is R1R2 = R2R1?

Is S1R2 = R2S1?

..

University ofUniversity ofBritish ColumbiaBritish Columbia

Example: Arbitrary Rotation

Problem: Given two orthonormal coordinate systems XYZand UVW Find transformation from one to the other

Answer: Transformation matrix R whose rows are U,V,W:

=

zyx

zyx

zyx

wwwvvvuuu

R

Y Z

X

W

V

U

University ofUniversity ofBritish ColumbiaBritish Columbia

Arbitrary Rotation

Proof:

Similarly R(Y) = V & R(Z) = W

R Xu u uv v vw w w

u u u

U

x y z

x y z

x y z

x y z

( ) ( , , )

( , , )

=

=

=

1 0 0

• 9

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Inverse (=transpose) transformation R-1provides mapping from UVW to XYZE.g.

Comment: Used for mapping between XY and arbitrary plane

Arbitrary Rotation (cont.)

X

uuu

wvuwvuwvu

uuuUR

zyx

zzz

yyy

xxx

zyx

==

++=

=

)0,0,1(

)0,0,(

),,()(

222

1

University ofUniversity ofBritish ColumbiaBritish Columbia

Lemma: Affine image of line segment is line segment between image of its end pointsProof:

Given affine transformation A & line segment

Conclusion: polyhedron(polygon) is affinelytransformed by transforming its vertices (Why?)

Transformation of Objects

)1()( 21 tPtPtS +=

)()1()())1(()(

))1(())((

21

21

21

PAtPtAtPAtPA

tPtPAtSA

+=+=

+=

University ofUniversity ofBritish ColumbiaBritish Columbia

Viewing Transformations

Question: How to view (draw) 3D object on 2D screen?Answer:

Project transformed object along Z axis onto XY plane -and from there to screen (space)Canonical projection:

1000000000100001

z

y

x

In practice ignore z axis use x and ycoordinates for screen coordinates

• 10

Computer GraphicsComputer Graphics

Transformations

University ofUniversity ofBritish ColumbiaBritish Columbia

Parallel Projection

Projectors are all parallel

Orthographic: Projectors perpendicular to projection plane

Oblique: Projectors not necessarily perpendicular to projection plane

ObliqueOrhtographic

University ofUniversity ofBritish ColumbiaBritish Columbia

Perspective Projection

Viewing is from point at finite distanceWithout loss of generality:

Viewpoint at originViewing plane is z=d

Given P=(x,y,z) triangle similarity gives:

dzyy

dzxx

dy

zy

dx

zx

pppp

/ and

/