Docsity

Unit 3 BCA computer graphics, Summaries of Computer Graphics and Animation

Partial preview of the text

Download Unit 3 BCA computer graphics and more Summaries Computer Graphics and Animation in PDF only on Docsity!

2D Transformations

x y x y x y

2D Transformation

 Given a 2D object, transformation is to

change the object’s

 Position (translation)  Size (scaling)  Orientation (rotation)  Shapes (shear)

 Apply a sequence of matrix multiplication to

the object vertices

Translation

 Re-position a point along a straight line

 Given a point (x,y), and the translation

distance (tx,ty)

The new point: (x’, y’) x’ = x + tx y’ = y + ty (^) (x,y) (x’,y’) OR P’ = P + T where P’ = x’ p = x T = tx y’ y ty tx ty

3x3 2D Translation Matrix

x’ = x + tx y’ y ty Use 3 x 1 vector x’ 1 0 tx x y’ = 0 1 ty * y 1 0 0 1 1

 Note that now it becomes a matrix-vector multiplication

2D Rotation

 Default rotation center: Origin (0,0)

θ θ> 0 : Rotate counter clockwise θ< 0 : Rotate clockwise θ

Rotation

(x,y) (x’,y’) θ (x,y) -> Rotate about the origin by θ (x’, y’) How to compute (x’, y’)? φ x = r cos (φ) y = r sin (φ) r x’ = r cos (φ + θ) y = r sin (φ + θ)

Rotation

(x,y) (x’,y’) θ φ r x’ = x cos(θ) – y sin(θ) y’ = y cos(θ) + x sin(θ) Matrix form? x’ cos(θ) -sin(θ) x y’ sin(θ) cos(θ) y = 3 x 3?

3x3 2D Rotation Matrix

x’ cos(θ) -sin(θ) x y’ sin(θ) cos(θ) y = (x,y) (x’,y’) θ φ r x’ cos(θ) -sin(θ) 0 x y’ sin(θ) cos(θ) 0 y 1 0 0 1 1 =

2D Scaling

Scale: Alter the size of an object by a scaling factor (Sx, Sy), i.e. x’ = x. Sx y’ = y. Sy x’ Sx 0 x y’ 0 Sy y

(1,1) (2,2) Sx = 2, Sy = 2 (2,2) (4,4)

2D Scaling

(1,1) (2,2) Sx = 2, Sy = 2 (2,2) (4,4)  Not only the object size is changed, it also moved!!  Usually this is an undesirable effect  We will discuss later (soon) how to fix it

Put it all together

 Translation: x’ x tx y’ y ty  Rotation: x’ cos(θ) -sin(θ) x y’ sin(θ) cos(θ) y  Scaling: x’ Sx 0 x y’ 0 Sy y = + = * = *

Or, 3x3 Matrix representations  Translation:  Rotation:  Scaling: Why use 3x3 matrices? x’ 1 0 tx x y’ = 0 1 ty * y 1 0 0 1 1 x’ cos(θ) -sin(θ) 0 x y’ sin(θ) cos(θ) 0 * y 1 0 0 1 1 = x’ Sx 0 0 x y’ = 0 Sy 0 * y 1 0 0 1 1

Rotation Revisit

 The standard rotation matrix is used to

rotate about the origin (0,0)

cos(θ) -sin(θ) 0 sin(θ) cos(θ) 0 0 0 1

 What if I want to rotate about an

arbitrary center?

Arbitrary Rotation Center

 To rotate about an arbitrary point P (px,py)

by θ:

 Translate the object so that P will coincide with the origin: T(-px, -py)  Rotate the object: R(θ)  Translate the object back: T(px,py) (px,py)