Docsity

Understanding Transformations in Computer Graphics: Translations, Scaling, Shearing, and R, Slides of Computer Graphics

Partial preview of the text

Download Understanding Transformations in Computer Graphics: Translations, Scaling, Shearing, and R and more Slides Computer Graphics in PDF only on Docsity!

Computer GraphicsIntroduction to Transforms, 2D transforms

Introduction to Transformations

n Transformation changes an objects: n Position (translation) n n Size (scaling)Orientation (rotation) n Shapes (shear) n We will introduce first in 2D or (x,y) , build intuition n Later, talk about 3D and 4D? n Transform object by applying sequence of matrixmultiplications to object vertices

Point Representation

n We use a column matrix (2x1 matrix) to represent a 2Dpoint

n General form of transformation of a point can be written as: (x,y) to (x’,y’)

 yx 

x '= ax + by + c y '= dx + ey + f

or 

y

x

d e f

a b c

y

x

Translation

n To reposition a point along a straight line n Given point (x,y) and translation distance (tx, ty) n The new point: (x’,y’) x’=x + tx y’=y + ty (x,y)

(x’,y’) or

P ' = P + T where P '^^ =^  xy '' P^ =^  xy  T =  ttxy 

Translation of Objects

ßHow to translate an object with multiple vertices?

Translate individualvertices

2D Scaling

ßScale: Alter object size by scaling factor (sx, sy). i.e

x’ = x. Sx

y’ = y. Sy

(1,1)

(2,2) Sx = 2, Sy = 2 (2,2)

(4,4)

 yx '' = Sx 0 Sy^0  yx 

Shearing

n Y coordinates are unaffected, but x cordinates are translatedlinearly with y n That is: n y’ = y n x’ = x + y * h 

 

 

 

∗ 

 

 

 

= 

 

 

 

 0 0 1 1

0 1 0 1 0 1

y h x y x

ßh is fraction of y to be added to x

2D Rotation

ßDefault rotation center is origin (0,0)

θ θ> 0 :^ Rotate counter clockwise

θ^ θ< 0 :^ Rotate clockwise

Rotation

(x,y)

(x’,y’) θ

x’ = x cos( θ ) – y sin( θ )^ r φ

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

Matrix form? 3 x 3?

 xy ''=^ cos(sin( θθ )) −cos(sin( θθ )) yx 

Using trig identities

cos( θ + φ ) =cos θ cos φ −sin θ sin φ

sin( θ + φ ) =sin θ cos φ +cos θ sin φ

3x3 2D Rotation Matrix

(x,y)

(x’,y’) θ

r φ

       = ^ −     y

x y

x sin( ) cos( )

cos( ) sin( ) '

' θ θ

θ θ



 

 

 

 

 

 

 

 −



 

 

 

 0 0 1 1

sin( ) cos( ) 0

cos( ) sin( ) 0 1

'

' y

x y

x θ θ

θ θ

Arbitrary Rotation Center

n To rotate about arbitrary point P = (Px, Py) by n Translate object by T(-Px, -Py) so that P coincides with origin θ : n n Rotate the object by R(Translate object back: T(Px, Py)θ) n In matrix form: T(Px,Py) R(θ) T(-Px,-Py) * P



sin( ) cos( ) 0

cos( ) sin( ) 0 0 0 1

y

x Py

Px Py

Px y

x θ θ

θ θ

ßSimilar for arbitrary scaling anchor,

Composing Transformation

n Composing transformation – applying several transformsin succession to form one overall transformation n Example: M1 X M2 X M3 X P where M1, M2, M3 are transform matrices applied to P n Be careful with the order n For example: n Translate by (5,0) then rotate 60 degrees is NOT same as n Rotate by 60 degrees then translate by (5,0)

References

n Hill, chapter 5.