2-D Trans
-
Upload
akanksha-gupta -
Category
Documents
-
view
5 -
download
1
description
Transcript of 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
2-D Transformation
x
y
x
y
x
y
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
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
+
Translation
• To translate an object with multiple vertices
Translate individualvertices
Rotation
• Default rotation center: Origin (0,0)
Rotate counter clockwise
Rotate clockwise
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)
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
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()
Rotation
• Rotation of an object with multiple vertices
Rotate individualVertices
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=
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
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,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
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• 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
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
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
B C
A’
B’ C’
Original Object
Reflected Object
Mirror Line
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
Reflection about Y-axis
–1 0 0 1
P (x, y)P (x’, y’)
Y
X
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
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
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
References
• Introduction to Computer Graphics by Udit Aggarwal
• www.morehouse.edu• www.cse.ohio-state.edu