2-D Trans

26

description

PPT on 2D Transformation

Transcript of 2-D Trans

Page 1: 2-D Trans
Page 2: 2-D Trans

Introduction

• 2-D Transformation is to change the object’s– Position (translation)– Size (scaling)– Orientation (rotation)– Shapes (shear)

• Objective of 2-D transformation– Simulate movement and manipulation of objects

• Apply a sequence of matrix multiplication to the object vertices

Page 3: 2-D Trans

2-D Transformation

x

y

x

y

x

y

Page 4: 2-D Trans

Point representation

• We can use a column vector (a 2x1 matrix) to represent a 2D point

• A general form of linear transformation can be

written as: x’ = ax + by + c

OR

y’ = dx + ey + f

X’ a b c xY’ = d e f * y1 0 0 1 1

XY

Page 5: 2-D Trans

Translation

• Rigid body transformation that moves objects without deformation

• 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’)

tx

ty

x’ = x tx y’ y ty

+

Page 6: 2-D Trans

Translation

• To translate an object with multiple vertices

Translate individualvertices

Page 7: 2-D Trans

Rotation

• Default rotation center: Origin (0,0)

Rotate counter clockwise

Rotate clockwise

Page 8: 2-D Trans

Rotation

• Rotation of (x,y) about origin by

(x,y)

(x’,y’)

r

x = r cos ()

y = r sin ()x’ = r cos ()

y’ = r sin ()

(x’, y’)(x, y)

Page 9: 2-D Trans

Rotation

• Rotation by transforms P(x,y) into P(x’,y’) x = r cos () y = r sin ()

x’ = r cos () y = r sin ()

x’ = r cos ()

= r cos() cos() – r sin() sin()

= x cos() – y sin()

y’ = r sin ()

= r sin() cos() + r cos()sin() = y cos() + x sin()

(x,y)

(x’,y’)

r

Page 10: 2-D Trans

Rotation

• Matrix form (Column Major order)

• The transformation matrix for rotation inAnticlockwise direction :

Clockwise direction :

[X’] = [X] [T] x’ cos() -sin() x y’ sin() cos() y

=

cos() -sin()sin() cos()

cos() sin()-sin() cos()

Page 11: 2-D Trans

Rotation

• Rotation of an object with multiple vertices

Rotate individualVertices

Page 12: 2-D Trans

Scaling

• Scale: Alter the size of an object by a scaling factor (Sx, Sy), i.e.

x’ = x . Sx y’ = y . Sy

(1,1)

(2,2)

Sx = 2, Sy = 2

(2,2)

(4,4)

x’ Sx 0 xy’ 0 Sy y=

Page 13: 2-D Trans

Scaling

• Uniform Scaling : if Sx = SyIf Sx = Sy > 1, then uniform expansion i.e object

becomes largerIf Sx = Sy < 1, then uniform compression i.e object

becomes smallerObject shape remains unaltered

Page 14: 2-D Trans

Scaling

• Non – Uniform Scaling : depends whether Sx and Sy individually > 1 or < 1 but unequal

• Non – Uniform Scaling also known as Differential Scaling

• Shape and size both change in differential scaling

Page 15: 2-D Trans

Scaling• Pure uniform Scaling :

Factors < 1 moves objects closer to origin Factors > 1 moves objects farther form origin

A’(40,22) D’(52,22)

B’(40,10) C’(52,10)

(20,11) (26,11)

(26,5)(20,5) A’’(40,5.5) C’’(52,5.5)

D’’(52.5.2)B’’(40,2.5)

Uniform Scaling

Sx = Sy = 2

Non–Uniform ScalingSx = 2 Sy = 0.5

Page 16: 2-D Trans

Shearing

• When applied to any object results in distortion of shape

• Opposite and parallel layers of object are slided with respect to each other

Page 17: 2-D Trans

X - Shear

• y co-ordinate remains unchanged• Transformation matrix for shear :

(0, 1)

(0, 0) (1, 0)

(1, 1)

X

Y Y

X(0, 0) (1, 0)

(3, 1)(2, 1)

Shear direction

=X’ Y X Y= *1 0 b 1 X + Yb Y

1 0b 1

Page 18: 2-D Trans

Y - Shear

• x co-ordinate remains unchanged• Transformation matrix for shear :

=X Y’ X Y= *1 a 0 1 X Xa + Y

Shea

r di

recti

on

1 a0 1

Page 19: 2-D Trans

Reflection

• Produces mirror image of an object• Image formed on the side opposite to where

the object is lying w.r.t mirror line• Perpendicular distance of object to mirror line

is same to the distance of the reflected image

Page 20: 2-D Trans

Reflection about X-axis

A

B C

A’

B’ C’

Original Object

Reflected Object

Mirror Line

Page 21: 2-D Trans

Reflection about X-axis

• x co-ordinate remains same• Sign of y co-ordinate changed• Reflection of point (x, y) in the x-axis gives

(x, -y)

x’y’

xy

= 1 00 -1

P (x, y)

P (x’, y’)

Y

X

Page 22: 2-D Trans

Reflection about Y-axis

–1 0 0 1

P (x, y)P (x’, y’)

Y

X

Page 23: 2-D Trans

Reflection about origin

• Mirror line is the axis perpendicular to the xy plane and passing through the origin

• After reflection both x and y coordinate of the object are flipped i.e.

x’ = – xy’ = – y

• Transformation Matrix :–1 0 0 –1

A

B

C

A’

B’

C’

Y

X

Page 24: 2-D Trans

Rotation about y = x

• Reflection of point P(x, y) about line y = x gives P’(x’, y’) i.e.x’ = yy’ = x

• Transformation Matrix : 0 1 1 0

Y

X

Page 25: 2-D Trans

Reflection about y = –x

• Reflection of point P(x, y) about line y = –x gives P’(x’, y’) i.e.x’ = – yy’ = – x

• Transformation Matrix : 0 –1 –1 0

Y

X

Page 26: 2-D Trans

References

• Introduction to Computer Graphics by Udit Aggarwal

• www.morehouse.edu• www.cse.ohio-state.edu