Vous êtes sur la page 1sur 26

Introduction

2-D Transformation is to change the objects


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

2-D Transformation
y

y x

Point representation
We can use a column vector (a 2x1 matrix) to represent a 2D point X Y A general form of linear transformation can be written as:
x = ax + by + c
X OR = Y 1 a d 0 b e 0 c f 1 * x y 1

y = dx + ey + f

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,y)
x = x + tx y = y + ty
= y x y
ty

(x,y)

tx

tx ty

Translation
To translate an object with multiple vertices

Translate individual vertices

Rotation
Default rotation center: Origin (0,0)

> 0

: Rotate counter clockwise

< 0

: Rotate clockwise

Rotation
Rotation of (x,y) about origin by
(x,y)

(x, y)

(x, y)

(x,y)

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

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

Rotation
Rotation by transforms P(x,y) into x =P(x,y) ) y = r sin ( ) r cos (
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)

Rotation
Matrix form (Column Major order)
[X] = [X] [T] x y
=

cos() sin()

-sin() cos()

x y

The transformation matrix for rotation in cos() sin()


-sin() Anticlockwise direction : cos() sin() -sin() cos()

cos()

Clockwise direction :

Rotation
Rotation of an object with multiple vertices

Rotate individual Vertices

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

x y

Sx 0 = 0 Sy

x y
(4,4)

Scaling
Uniform Scaling : if Sx = Sy
If Sx = Sy > 1, then uniform expansion i.e object becomes larger If Sx = Sy < 1, then uniform compression i.e object becomes smaller Object shape remains unaltered

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

Scaling
Pure uniform Scaling :
Factors < 1 moves objects closer to origin Factors > 1 moves objects farther form origin
A(40,2 2) (20,1 1) (26,1 1)
rm nifo ng 2 U i ca l = S= Sy Sx

D(52,2 2)

(20,5)

(26,5)

Non Un Sca iform ling Sx = 2 Sy =0 .5

B(40,1 0) A(40,5 .5) B(40,2

C(52,1 0) C(52,5. 5) D(52.5.

Shearing
When applied to any object results in distortion of shape

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

X - Shear
y co-ordinate remains unchanged 1 : Transformation matrix for shear 0 b 1
X Y = X
Y (0, 1) (1, 1) X

Y *

1 b

0 1
Y

= + Yb X
Shear (3, direction 1)

(2, 1)

(0, 0)

(1, 0)

(0, 0) (1, 0)

Y - Shear
x co-ordinate remains unchanged Transformation matrix for shear a 1 : 0 1
X Y = X Y * 1 0 a 1 =X
Shear directio n

Xa + Y

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

Reflection about X-axis


A Original Object

C Mirror Line

C Reflected Object A

Reflection about X-axis


x co-ordinate remains same Sign of y co-ordinate changed Reflection of point (x, y) in the x-axis Y gives P (x, y) (x, -y) x =1 0x P (x, y 0 -1 y y)

Reflection about Y-axis

Y P (x, y) P (x, y) X

1 0

0 1

Reflection about origin


Mirror line is the axis perpendicular to the xy plane and passing through the origin After reflection both x and yY B coordinate of the object are flipped i.e. C A A x = x C 1 y = y B Transformation Matrix : 0 0

Rotation about y = x
Reflection of point P(x, y) about line y = x gives P(x, y) i.e. Y x = y y = x Transformation Matrix : X 0 1 1 0

Reflection about y = x
Reflection of point P(x, y) about line y = x gives P(x, y) i.e. Y x = y y = x Transformation Matrix : X 0 1 1 0

References
Introduction to Computer Graphics by Udit Aggarwal www.morehouse.edu www.cse.ohio-state.edu

Vous aimerez peut-être aussi