lecture notes: computer graphics. why transformations? in graphics, once we have an object...

29
Lecture Notes: Computer Graphics

Upload: silas-fitzgerald

Post on 12-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Lecture Notes:

Computer Graphics

Page 2: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Why Transformations?

• In graphics, once we have an object described, transformations are used to move that object, scale it and rotate it

Page 3: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Transformation

• Two complementary views– Geometric trans: Object is transformed relative to a stationary

coordinate system

– Coordinate trans: Object is held stationary while the coordinate system is transformed

• Ex: moving an automobile against a scenic background– Move the auto and keep the background fixed (GT)

– Keep the car fixed and move the background (CT)

Page 4: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Basic 2D Geometric Transformations

• Four basic types– Translation

– Scaling

– Rotation

– Shear (possible using a combination of rotation and scaling)

Page 5: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Translation

• Simply moves an object from one position to another

xnew = xold + tx ynew = yold + ty

Note: House shifts position relative to origin

y

x 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

Page 6: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Scaling

• Scalar multiplies all coordinates

• WATCH OUT: Objects grow and move!

xnew = Sx × xold ynew = Sy × yold

Note: House shifts position relative to origin

y

x 0

1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

1

2

1

3

3

6

3

9

Page 7: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Rotation

• Rotates all coordinates by a specified angle

xnew = xold × cosθ – yold × sinθ

ynew = xold × sinθ + yold × cosθ

• Points are always rotated about the origin

6

y

x 0 1

1

2

2

3 4 5 6 7 8 9 10

3

4

5

6

Page 8: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Shear

• Along X-axis

• Along Y-axis

yhxxx s

xhyyy s

Page 9: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Basic 2D Geometric Transformations

• Translation– –

• Scale– –

• Rotation– –

• Shear

– –

txxx tyyy

sxxx syyy

sinθy-cosθxx cosθysinθxy

yhxxx sxhyyy s

Page 10: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Transformation and Matrix Multiplication

• Recall how matrix multiplication takes place:

ziyhxg

zfyexd

zcybxa

z

y

x

ihg

fed

cba

***

***

***

Page 11: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Matrix Representation

• Represent a 2D Transformation by a Matrix

• Apply the Transformation to a Point

y

x

dc

ba

y

x

dycxy

byaxx

dc

ba

TransformationMatrix Point

Page 12: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Matrix Representation

• Transformations can be combined by matrix multiplication

y

x

lk

ji

hg

fe

dc

ba

y

x

Matrices are a convenient and efficient way

to represent a sequence of transformations

TransformationMatrix

Page 13: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

2×2 Matrices

• What types of transformations can be represented with a 2×2 matrix?

2D Identity

2D Scaling

yy

xx

ysyy

xsxx

y

x

y

x

10

01

y

x

sy

sx

y

x

0

0

Page 14: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

2×2 Matrices

• What types of transformations can be represented with a 2×2 matrix?

2D Rotation

2D Shearing

y

x

y

x

cossin

sincos

y

x

shy

shx

y

x

1

1

yxy

yxx

cossin

sincos

yxshyy

yshxxx

Page 15: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

2×2 Matrices

• What types of transformations can be represented with a 2×2 matrix?

2D Mirror over Y axis

2D Mirror over (0,0)

yy

xx

yy

xx

y

x

y

x

10

01

y

x

y

x

10

01

Page 16: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

2×2 Matrices

• What types of transformations can be represented with a 2×2 matrix?

2D Translation

txxx tyyy

NO!!

Only linear 2D transformationscan be Represented with 2x2 matrix

Page 17: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Homogeneous Coordinates

• A point (x, y) can be re-written in homogeneous coordinates as (xh, yh, h)

• The homogeneous parameter h is a non-zero value such that:

• We can then write any point (x, y) as (hx, hy, h)

• We can conveniently choose h = 1 so that (x, y) becomes (x, y, 1)

h

xx h

h

yy h

Page 18: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Homogeneous Coordinates

• Add a 3rd coordinate to every 2D point– (x, y, w) represents a point at location (x/w, y/w)

– (x, y, 0) represents a point at infinity

– (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 to

Represent Many Useful Transformations

Page 19: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Why Homogeneous Coordinates?

• Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations

• We will see in a moment that all of the transformations we discussed previously can be represented as 3*3 matrices

• Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!

Page 20: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Homogeneous Translation

•The translation of a point by (dx, dy) can be written in matrix form as:

• Representing the point as a homogeneous column vector we perform the calculation as:

100

10

01

dy

dx

11*1*0*0

1**1*0

1**0*1

1100

10

01

dyy

dxx

yx

dyyx

dxyx

y

x

dy

dx

Page 21: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Homogenous Coordinates

• To make operations easier, 2-D points are written as homogenous coordinate column vectors

vdydxTvdyy

dxx

y

x

dy

dx

),(':

11100

10

01

vssSvys

xs

y

x

s

s

yxy

x

y

x

),(':

11100

00

00

Translation:

Scaling:

Page 22: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Basic 2D Transformations

• Basic 2D transformations as 3x3 Matrices

1100

10

01

1

y

x

ty

tx

y

x

1100

0cossin

0sincos

1

y

x

y

x

1100

00

00

1

y

x

sy

sx

y

x

1100

01

01

1

y

x

shy

shx

y

x

Translate

Shear

Scale

Rotate

Page 23: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Combining Transformations

•A number of transformations can be combined into one matrix to make things easy

– Allowed by the fact that we use homogenous coordinates

• Imagine rotating a polygon around a point other than the origin

– Transform to centre point to origin

– Rotate around origin

– Transform back to centre point

Page 24: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Matrix Composition

• Transformations can be combined by matrix multiplication

• Efficiency with premultiplication

– Matrix multiplication is associative

w

y

x

1 0 0

0sy0

00sx

1 0 0

0cosθinθ

0 sinθ- θcos

100

10

01

sty

tx

w

y

x

p ty)T(tx, )R( sy)S(sx, p

p)))S(R(T(p pS)RT(p

Page 25: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Combining Transformations (cont…))(HHouse HdydxT ),(

HdydxTR ),()( HdydxTRdydxT ),()(),(

1 2

3 4

Page 26: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Combining Transformations (cont…)

• The three transformation matrices are combined as follows

1100

10

01

100

0cossin

0sincos

100

10

01

y

x

dy

dx

dy

dx

REMEMBER: Matrix multiplication is not commutative so order matters

vdydxTRdydxTv ),()(),('

Page 27: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Matrix Composition

• Rotate by around arbitrary point (a,b)

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

a,-b-TRba,TM θ

a,-b-Tsysx,Sba,TM

(a,b)

(a,b)

Page 28: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Inverse Transformations

•Transformations can easily be reversed using inverse transformations

100

10

011 ty

tx

T

100

01

0

001

1

y

x

s

s

S

100

0cossin

0sincos1

R

Page 29: Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale

Basic 2D Coordinate Transformations

• Translation

• Scale

• Rotation

• Shear ??

txxx tyyy

sx)/1(xx

sy)/1(yy

sinθycosθxx cosθysinθxy