lect6 transformation2d

38
Graphics [email protected] 2D Geometric Transformations Sudipta Mondal

Upload: bcet

Post on 19-May-2015

643 views

Category:

Documents


3 download

DESCRIPTION

created by Sudipta mandal

TRANSCRIPT

Page 1: Lect6 transformation2d

Graphics

[email protected]

2D GeometricTransformations

Sudipta Mondal

Page 2: Lect6 transformation2d

BCETContents

n Definition & Motivationn 2D Geometric Transformation

n Translationn Rotationn Scaling

n Matrix Representationn Homogeneous Coordinatesn Matrix Compositionn Composite Transformations

n Pivot-Point Rotationn General Fixed-Point Scalingn Reflection and Shearingn Transformations Between Coordinate Systems

Page 3: Lect6 transformation2d

BCETGeometric Transformation

n Definitionn Translation, Rotation, Scaling.

n Motivation – Why do we need geometrictransformations in CG?n As a viewing aidn As a modeling tooln As an image manipulation tool

Page 4: Lect6 transformation2d

BCET

Example: 2D GeometricTransformation

ModelingCoordinates

World Coordinates

Page 5: Lect6 transformation2d

BCETExample: 2D Scaling

ModelingCoordinates

World Coordinates

Scale(0.3, 0.3)

Page 6: Lect6 transformation2d

BCETExample: 2D Rotation

ModelingCoordinates

Scale(0.3, 0.3)Rotate(-90)

World Coordinates

Page 7: Lect6 transformation2d

BCETExample: 2D Translation

ModelingCoordinates

Scale(0.3, 0.3)Rotate(-90)Translate(5, 3)

World Coordinates

Page 8: Lect6 transformation2d

BCET

Example: 2D GeometricTransformation

ModelingCoordinates

World Coordinates

Again?

Page 9: Lect6 transformation2d

BCET

Example: 2D GeometricTransformation

ModelingCoordinates

World Coordinates

ScaleTranslate

ScaleRotate

Translate

Page 10: Lect6 transformation2d

BCETBasic 2D Transformations

n Translationn

n

n Scalen

n

n Rotationn

n

n Shearn

n

txxx +=¢tyyy +=¢

sxxx ´=¢syyy ´=¢

sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢

yhxxx ´+=¢xhyyy ´+=¢

Page 11: Lect6 transformation2d

BCETBasic 2D Transformations

n Translationn

n

n Scalen

n

n Rotationn

n

n Shearn

n

txxx +=¢tyyy +=¢

sxxx ´=¢syyy ´=¢

sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢

yhxxx ´+=¢xhyyy ´+=¢

Transformationscan be combined

(with simple algebra)

Page 12: Lect6 transformation2d

BCETBasic 2D Transformations

n Translationn

n

n Scalen

n

n Rotationn

n

n Shearn

n

txxx +=¢tyyy +=¢

sxxx ´=¢syyy ´=¢

sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢

yhxxx ´+=¢xhyyy ´+=¢

syysxxx

´=¢´=¢

y

Page 13: Lect6 transformation2d

BCET

)cossy)(ysinsx)((xy)sinsy)(ycossx)((xx

qqqq

´´+´´=¢´´-´´=¢

Basic 2D Transformations

n Translationn

n

n Scalen

n

n Rotationn

n

n Shearn

n

txxx +=¢tyyy +=¢

sxxx ´=¢syyy ´=¢

sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢

yhxxx ´+=¢xhyyy ´+=¢

Page 14: Lect6 transformation2d

BCET

ty)cossy)(ysinsx)((xytx)sinsy)(ycossx)((xx

+´´+´´=¢+´´-´´=¢

qqqq

Basic 2D Transformations

n Translationn

n

n Scalen

n

n Rotationn

n

n Shearn

n

txxx +=¢tyyy +=¢

sxxx ´=¢syyy ´=¢

sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢

yhxxx ´+=¢xhyyy ´+=¢

Page 15: Lect6 transformation2d

BCETBasic 2D Transformations

n Translationn

n

n Scalen

n

n Rotationn

n

n Shearn

n

txxx +=¢tyyy +=¢

sxxx ´=¢syyy ´=¢

sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢

yhxxx ´+=¢xhyyy ´+=¢

ty)cossy)(ysinsx)((xytx)sinsy)(ycossx)((xx

+´´+´´=¢+´´-´´=¢

qqqq

Page 16: Lect6 transformation2d

BCETMatrix Representation

n Represent a 2D Transformation by a Matrix

n Apply the Transformation to a Point

úû

ùêë

éúû

ùêë

é=ú

û

ùêë

颢

yx

dcba

yx

dycxybyaxx

+=¢+=¢

úû

ùêë

édcba

TransformationMatrix Point

Page 17: Lect6 transformation2d

BCETMatrix Representation

n Transformations can be combined by matrixmultiplication

úû

ùêë

éúû

ùêë

éúû

ùêë

éúû

ùêë

é=ú

û

ùêë

颢

yx

lkji

hgfe

dcba

yx

Matrices are a convenient and efficient wayto represent a sequence of transformations

TransformationMatrix

Page 18: Lect6 transformation2d

BCET2×2 Matrices

n What types of transformations can berepresented with a 2×2 matrix?2D Identity

2D Scalingyyxx

=¢=¢

ysyyxsxx

´=¢´=¢

úû

ùêë

éúû

ùêë

é=ú

û

ùêë

颢

yx

yx

1001

úû

ùêë

éúû

ùêë

é=ú

û

ùêë

颢

yx

sysx

yx

00

Page 19: Lect6 transformation2d

BCET2×2 Matrices

n What types of transformations can berepresented with a 2×2 matrix?2D Rotation

2D Shearing

úû

ùêë

éúû

ùêë

é -=ú

û

ùêë

颢

yx

yx

qqqq

cossinsincos

úû

ùêë

éúû

ùêë

é=ú

û

ùêë

颢

yx

shyshx

yx

11

yxyyxx

´+´=¢´-´=¢

qqqq

cossinsincos

yxshyyyshxxx

+´=¢´+=¢

Page 20: Lect6 transformation2d

BCET2×2 Matrices

n What types of transformations can berepresented with a 2×2 matrix?2D Mirror over Y axis

2D Mirror over (0,0)yyxx

=¢-=¢

yyxx

-=¢-=¢

úû

ùêë

éúû

ùêë

é-=ú

û

ùêë

颢

yx

yx

1001

úû

ùêë

éúû

ùêë

é-

-=ú

û

ùêë

颢

yx

yx

1001

Page 21: Lect6 transformation2d

BCET2×2 Matrices

n What types of transformations can berepresented with a 2×2 matrix?2D Translation

txxx +=¢tyyy +=¢ NO!!

Only linear 2D transformationscan be Represented with 2x2 matrix

Page 22: Lect6 transformation2d

BCETHomogeneous Coordinates

nA point (x, y) can be re-written in homogeneouscoordinates as (xh, yh, h).nThe homogeneous parameter h is a non-zero value such that:

nWe can then write any point (x, y) as (hx, hy, h)nWe can conveniently choose h = 1 so that(x, y) becomes (x, y, 1)

hxx h=

hyy h=

Page 23: Lect6 transformation2d

BCET

Why HomogeneousCoordinates?

nMathematicians commonly use homogeneouscoordinates as they allow scaling factors to beremoved from equations.nWe will see in a moment that all of thetransformations we discussed previously can berepresented as 3*3 matrices.nUsing homogeneous coordinates allows us usematrix multiplication to calculate transformations –extremely efficient!

Page 24: Lect6 transformation2d

BCETHomogeneous Translation

nThe translation of a point by (dx, dy) can bewritten in matrix form as:

nRepresenting the point as a homogeneouscolumn vector we perform the calculation as:

úúú

û

ù

êêê

ë

é

1001001

dydx

úúú

û

ù

êêê

ë

é++

=úúú

û

ù

êêê

ë

é

++++++

=úúú

û

ù

êêê

ë

é´úúú

û

ù

êêê

ë

é

11*1*0*01**1*01**0*1

11001001

dyydxx

yxdyyxdxyx

yx

dydx

Page 25: Lect6 transformation2d

BCET2D Translation

n 2D translation can be represented by a 3×3matrixn Point represented with homogeneous coordinates

txxx +=¢tyyy +=¢

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é=

úúú

û

ù

êêê

ë

颢

11001001

1yx

tytx

yx

Page 26: Lect6 transformation2d

BCETBasic 2D Transformations

n Basic 2D transformations as 3x3 Matrices

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é=

úúú

û

ù

êêê

ë

颢

11001001

1yx

tytx

yx

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é -=

úúú

û

ù

êêê

ë

颢

11000cossin0sincos

1yx

yx

qqqq

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é=

úúú

û

ù

êêê

ë

颢

11000000

1yx

sysx

yx

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é=

úúú

û

ù

êêê

ë

颢

11000101

1yx

shyshx

yx

Translate

Shear

Scale

Rotate

Page 27: Lect6 transformation2d

BCETHomogeneous Coordinates

n Add a 3rd coordinate to every 2D pointn (x, y, w) represents a point at location (x/w, y/w)n (x, y, 0) represents a point at infinityn (0, 0, 0) is not allowed

1 2

1

2

x

y

(2, 1, 1) or (4, 2, 2) or (6, 3, 3)

Convenient Coordinate System toRepresent Many Useful Transformations

Page 28: Lect6 transformation2d

BCETLinear Transformations

n Linear transformations are combinations of …n Scalen Rotationn Shear, andn Mirror

n Properties of linear transformationsn Satisfies:n Origin maps to originn Lines map to linesn Parallel lines remain paralleln Ratios are preservedn Closed under composition

)()()( 22112211 pTspTspspsT +=+

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é=

úúú

û

ù

êêê

ë

é

¢¢¢

wyx

dcba

wyx

10000

Page 29: Lect6 transformation2d

BCETAffine Transformations

n Affine transformations are combinations ofn Linear transformations, andn Translations

n Properties of affine transformationsn Origin does not map to originn Lines map to linesn Parallel lines remain paralleln Ratios are preservedn Closed under composition

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é=

úúú

û

ù

êêê

ë

é

¢¢¢

wyx

fedcba

wyx

100

Page 30: Lect6 transformation2d

BCETMatrix Composition

n Transformations can be combined by matrixmultiplication

n Efficiency with premultiplicationn Matrix multiplication is associative

úúú

û

ù

êêê

ë

é

÷÷÷

ø

ö

ççç

è

æ

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é

úúú

û

ù

êêê

ë

é=

úúú

û

ù

êêê

ë

é

¢¢¢

wyx

1000sy000sx

1000cosθinθ0sinθ-θcos

1001001

stytx

wyx

=¢p ty)T(tx, )R(q sy)S(sx, p

p)))S(R(T(p ´´´=¢ pS)RT(p ´´´=¢

Page 31: Lect6 transformation2d

BCETMatrix Composition

n Rotate by q around arbitrary point (a,b)n

n Scale by sx, sy around arbitrary point (a,b)n

T(-a,-b))R(b)T(a,M ´´= θ

T(-a,-b)sy)S(sx,b)T(a,M ´´=

(a,b)

(a,b)

Page 32: Lect6 transformation2d

BCETInverse Transformations

nTransformations can easily be reversed usinginverse transformations

úúú

û

ù

êêê

ë

é--

=-

1001001

1 dydx

T

úúúúúú

û

ù

êêêêêê

ë

é

=-

100

010

001

1

y

x

s

s

S

úúú

û

ù

êêê

ë

é-=-

1000cossin0sincos

1 qqqq

R

Page 33: Lect6 transformation2d

BCETPivot-Point Rotation

úúú

û

ù

êêê

ë

é--+--

=úúú

û

ù

êêê

ë

é--

×úúú

û

ù

êêê

ë

é -×úúú

û

ù

êêê

ë

é

100sin)cos1(cossinsin)cos1(sincos

1001001

1000cossin0sincos

1001001

qqqqqqqq

qqqq

rr

rr

r

r

r

r

xyyx

yx

yx

( ) ( ) ( ) ( )qq ,,,, rrrrrr yxRyxTRyxT =--××

Translate Rotate Translate

(xr,yr) (xr,yr) (xr,yr)(xr,yr)

Page 34: Lect6 transformation2d

BCETGeneral Fixed-Point Scaling

úúú

û

ù

êêê

ë

é--

=úúú

û

ù

êêê

ë

é--

×úúú

û

ù

êêê

ë

é×

úúú

û

ù

êêê

ë

é

100)1(0)1(0

1001001

1000000

1001001

yfy

xfx

f

fx

f

f

syssxs

yx

ss

yx

y

Translate Scale Translate

(xf,yf) (xf,yf) (xf,yf) (xf,yf)

( ) ( ) ( ) ( )yxffffyxff ssyxSyxTssSyxT ,,,, ,, =--××

Page 35: Lect6 transformation2d

BCETReflection

n Reflection with respect to the axis• x • y • xy

úúú

û

ù

êêê

ë

é-

100010001

úúú

û

ù

êêê

ë

é-

100010001

úúú

û

ù

êêê

ë

é-

-

100010001

Y AXISX AXIS XY AXIS

x

y 1

32

1’

3’2’x

y1

32

1’

3’ 2

x

y

3

1’

3’ 2

1

2

Page 36: Lect6 transformation2d

BCET

n Reflection with respect to a Line

n Clockwise rotation of 45 ® Reflection about the xaxis ® Counterclockwise rotation of 45

Reflection

úúú

û

ù

êêê

ë

é

100001010

y=x

x

y 1

32

1’

3’2’x

y

x

y

x

y

°

°

Page 37: Lect6 transformation2d

BCETShear

n Converted to a parallelogram

x’ = x + shx · y, y’ = y

n Transformed to a shifted parallelogram(Y = Yref)

x’ = x + shx · (y-yref), y’ = y

úúú

û

ù

êêê

ë

é

10001001 xsh

úúú

û

ù

êêê

ë

é ×-

100010

1 refxx yshsh

x (Shx=2)

(Shx=1/2, yref=-1)

x

y

x

y

x

y

x

y

(0,0) (1,0)

(1,1)(0,1)

(0,0) (1,0)

(1,1)(0,1)

(0,0) (1,0)

(3,1)(2,1)

(1/2,0)(3/2,0)

(2,1)(1,1)

(0,-1)

Page 38: Lect6 transformation2d

BCETShear

n Transformed to a shifted parallelogram(X = Xref)

x’ = x, y’ = shy · (x-xref) + y

úúú

û

ù

êêê

ë

é×-

1001

001

refyy xshsh

(Shy=1/2, xref=-1)

x

y

x

y

(-1,0)(0,0) (1,0)

(1,1)(0,1)(0,1/2) (1,1)

(1,2)(0,3/2)