0% found this document useful (0 votes)
18 views

Computer Graphics-PPT - CH3

Uploaded by

vap3x97
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Computer Graphics-PPT - CH3

Uploaded by

vap3x97
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 85

CHAPTER 3

TWO DIMENSIONAL GEOMETRIC


TRANSFORMATIONS
Content

 3.1 Basic transformations: Translation, Scaling, Rotation


 3.2 Matrix representation and Homogeneous Coordinates
 3.3 Composite transformation
 3.4 Other transformations: Reflection and Shear
What is Transformation?

 Transformation is the process of modifying or changing the


image.
 It involves changing the position, size, orientation or shape
of the image.
Why Transformation??

 The computer graphics systems are mainly used in animating the


object.
 The animation mainly deals with moving and manipulating the object.
 This can be achieved by performing various transformations such as
translation, rotation , scaling , reflection etc. on the object.
Types of transformations

 Geometric transformation : Object is moved while the relative


coordinate system (or back ground) is kept stationery or fixed. This
geometric transformations are applied to each point of the object.

 Coordinate transformation: The object is kept stationery while the


coordinate system (or background) is moved relative to the object. Thus
the transformation are applied to the coordinate system of the object.
What is Transformation ?

 There are basic five types of transformation that can be applied on any 2D shape.
1) Translation
2) Rotation
3) Scaling
4) Reflection
5) Shear
Translation

 Translation is the process of repositioning the object in a straight line path from one
coordinate position to another.
 We define the translation vector (tx , ty).
 tx defines movement of the object in X – direction and ty defines the movement of the
object in Y-direction.
 Assuming point P(X,Y) needs to be translated to position P’(X’,Y’).
 This can be obtained by simply adding tx to X and Ty to y
X’= X + tx
Y’ = Y + ty
OR
P’ = P + T where
 P = [ X Y ] , P’ = [X’ Y’ ] and T =[tx ty]
Translation
Example:

 Translate a polygon with coordinates A(2,5) , B(7,10) and C(10,2) by 3


units in X-direction and 4 units in Y-Direction.
Solution:
Rotation

 2D rotation is applied to an object by


repositioning it along a circular path
in XY plane.
 To generate a rotation we specify
1) Rotation angle θ
2) (Xr, Yr) also called pivot (or fixed)
point about which the object is to be
rotated.
 Positive values of θ -> counter clock
wise rotation
 Negative value of θ -> clock wise
rotation
Derive rotation matrix w.r.t. origin
 Let r is the constant distance form the origin (radius)
 Angle Ø is the original angular position of the point (x,y) and θ is the rotation angle.
x’ = r cos (θ + Ø)= r cosθ cosØ – r sinθ sinØ ……. (1)
Y’ = r sin (θ + Ø) = r cosθ sinØ + r sinθ cosØ ……..(2)
 Now we know that original coordinates
X = r cosØ
Y = r sinØ
 Substituting these values in (1) and (2) we get
X’ = x cosθ – y sinθ
Y’ = x sinθ + y cosθ
X’ = X cosθ – Y sinθ
Y’ = x sinθ + y cosθ

For Negative values of θ matrix can be given as


EXAMPLE: Rotation
Scaling

 A scaling alters the size of an object.


 This operation can be carried out for a polygon by multiplying the
coordinates value (x,y) of each vertex by scaling factor Sx and Sy to
produce the transformed coordinates (x’,y’)
X’ = X. Sx
Y’ = Y . Sy
 Scaling factor Sx scales the object in X – direction and Sy scales in Y -
direction
 The above transformation can be given in matric form as
 Any positive number can be assigned to scaling factor
Sx and Sy.
 Scaling factor < 1 reduces the size of the object.
 Scaling factor > 1 enlarges the object
 Scaling factor =1 doesn’t change object
 When Sx = Sy , a uniform scaling is produced.
 Unequal values of Sx and Sy results in a differential
scaling.
 Note that in figure , object is scaled as well as
repositioned.
 Observe that the line is reduced in size and moved Fig: A line is scaled with
closer to the origin by a factor of 1/2 Sx=Sy=0.5
Scaling with respect to fixed point

 For a vertex with coordinates (x,y) and a fixed pivot point (xf,yf), the
scaled coordinates (x’,y’) are calculated as,
x’ = xf + (x – xf) .Sx
y’ = yf + (y – yf).Sy
OR
X’ = x . Sx + xf (1-Sx)
Y’ = y . Sy + yf (1-Sy)
EXAMPLE: SCALING
Homogenous Coordinates

 Many graphics applications involve sequence of transformations.


 An animation for example might require an object to be translated then
rotated and then scaled at each increment of the motion.
 In design and picture formation process, we may require to perform
translation, rotations and scaling to fit the picture components into
their proper positions.
 We know that each of the basic transformations(i.e. translation ,
rotation and scaling) can be expresses in the general matric form,

Row order Column Order


P’ = P . M1 + M2 P’ = M1.P + M2

 Here matrix M1 is a 2x2 matrix and M2 is a two element matrix


containing translation term.
 With this method, to produce a series of transformations such as translation followed by
rotation and the scaling , we must calculate the transformed coordinates one step at a item.
 First coordinates are translated, then these translated coordinates are rotated and then
rotated coordinates are then scaled.
 A more efficient approach is o combine sequence of transformations into one
transformation so that the final coordinate positions are obtained directly form initial
coordinates.
 This eliminates calculation of intermediate coordinate values.
 In order to combine these sequence of transformations we need to eliminate the matrix
addition. Associated with the translation.
 To achieve this we have to represent all matrix as 3x3 by introducing an additional dummy
coordinate h. Here we represent each Cartesian coordinate position(x,y) with homogenous
coordinate triplet (Xh, Yh ,h )
 Where X = Xh / h , Y = Yh / h
 In general the homogenous coordinate representation can also be
written as ( x.h , y.h , h)
 For 2D geometric transformation, we can choose any non-zero value of
h but for simplicity usually h is taken as 1.
 So homogenous coordinate becomes (x ,y, 1)
 Homogenous coordinates allow combined transformations, eliminating
the calculation of intermediate coordinate values and thus save
required time for transformation and also reduce required memory.
Homogenous coordinates for
Translation
Homogenous coordinates for
Rotation
Homogenous coordinates for scaling
EXAMPLE:

 Give a 3x3 homogenous coordinate transformation matrix for each of


the following translations.
1) Shift the image to the right 3 – units
2) Shift the image up 2 –units
3) Move the image ½ unit down and 1 unit to the right.
Solution

1) Shift the image to 2) Shift the image up 3) Move the image ½


the right 3 – units 2 –units unit down and 1 unit
to the right.
EXAMPLE 1:

 Find the transformation matrix that transforms the given square ABCD to half
its size with center still remaining at the same position. The coordinates of the
square are A(1,1), B(3,1), c (3,3) and D (1,3). Also find the resultant
coordinates of square.
Solution

 The transformation can be carried out by applying following


transformations in series.
 1) Translate the square so that its center coincides with the origin
 2) Scale the square with respect to origin
 3) Translate the square back to the original position
Prove that two successive translations are
additive
Prove that two successive rotations are additive
Prove that two successive scaling are
multiplicative
General Pivot point Rotation
(Rotation with respect to Fixed Point) IMP

 We can generate rotation about any fixed point (called pivot point) (Xr,Yr)
by performing following sequence of Translate – Rotate – Translate.
1) Translate the object so that the pivot point is moved to the coordinate
origin
2) Rotate the object about the origin
3) Translate the object so that the pivot point is returned to its original
position.
Sequence of transformation for rotation w.r.t fixed
point
Fixed point scaling

 To scale an object with respect to a selected fixed point (or pivot point)
say (Xf,Yf) perform the following operations.

1) Translate object so that the fixed point coincides with the origin
2) Scale the object with respect to the origin.
3) Use the inverse translation of step (1) to return bring the object
back to its original position.
Sequence of transformations for
scaling w.r.t fixed point
Derivation – Scaling w.r.t fixed point
General Scaling Direction

 Parameters Sx and Sy scales the object along the


X and Y direction respectively.
 We can scale an object in other directions by
rotating an object to align the desired scaling
directions with the coordinate axes before
applying the scaling transformation.
 Suppose we want to apply scaling factors with
values s1 and s2 in the directions shown in the
fig.
 To accomplish the scaling without changing the orientation of the
object,
1) We first perform a rotation so that the direction s1 and s2 coincides
with X and Y axis resp.
2) Then scaling transformation is applied
3) And then Inverse rotation is applied
Example

 Consider a square with coordinates as (0,0), (0,1), (1,0) and (1,1). If the above
transformation is applied to the square along a diagonal form (0,0) to (1,1). ,
the square gets turned into a parallelogram as shown in the figure below.
Consider
S1 = 1 and S2 = 2.
Solution: Here we rotate the diagonal onto the Y – axis and double its length with
the transformation parameters θ=45 , s1 = 1 , s2 = 2.
Before After
Reflection

 A Reflection is a transformation that produces a mirror image of an


object.
 The mirror image for a 2D reflection is generated relative to an axis of
reflection by rotating the object 180 about the reflection axis.
 We can choose an axis of reflection in the XY plane or perpendicular to
the XY plane.
Reflection of an object about y=x
line

 Sequence of transformations
 1) Rotate the line y=x by an angle 45 clock
wise so that it coincides with X- Axis.
 2) Reflect an object about X- axis
 3) Perform inverse rotation
Reflection of an object about Line
Y=-X

 Sequence of transformation.
1) Rotate the line Y=-X by an angle 45 in clockwise
direction so that it coincides with the Y – axis.
2) Perform Reflection about Y-axis.
3) Perform the inverse rotation.
Reflection of an object about
arbitrary line y=mx+c (IMP)

 The sequence of transformations are


1) Translate the line Y= mx+c so that point (0,c) i.e.
Y-intercept of line coincides with the origin.
2) Rotate the line y= mx +c by and angle θ in
clockwise direction so that the line coincides with
X- axis.
3) Perform reflection about X-axis
4) Perform Inverse rotation
5) Perform Inverse Translation
SHEAR

 Transformation that slants the shape of the object is called shear


transformation.
 Two common shear transformations are : X – Sher and Y-shear.
 X-shear shifts the X-coordinate values and preserves the Y coordinate
values.
 Y-shear shifts the Y-coordinate values and preserves the X coordinate
values.
X-Shear
X-Shear

[x’ y’ 1] = [ x y 1]

 Any real number can be assigned to shear parameter.


 A coordinate position (x,y) is then shifted horizontally by an amount
proportional to its Y value.
 Setting Shx to negative value shifts the coordinates positions to the left.
Y-Shear

 The Y-Shear preserves the X-coordinates, but changes the Y –values.


PROBLEMS ON ROTATION
Note: All problems are solved using Row measure matrix
Problem1:

Given a line A(2,3) to B(2,10)


A) Rotate the line by 90 degree counter clock wise.
B) Rotate the line by 90 degree counter clock wise by keeping point A as
fixed point

B(2,10)

A(2,3)
Solution (A)
(A) Here θ =90 ( we use row measure)
So R = = After Rotation Original

B(2,10
)
P’ = P . R
B’(-10,2) A’(-3,2)
= A(2,3)

So final Rotated coordinates are


A’(-3,2) and B’(-10,2)
Solution (B) (We use row
measure)
 We perform T(-2,-3) . R(90), T(2,3) Now
P’ = P . M

M= =

= =

= So Final rotated points are


A’(2,3) and B’(-5,3)

This is final transformation matrix


 HOME WORK : solve the same problem by considering Clock wise rotation
i.e. θ = - 90
Problem 2:

Find a transformation of a triangle A(1,0), B(0,1) and C(1,1) by


A) Rotating 90 degree about the origin and then translating one
unit in X and one unit y direction.
B) Translating one unit in x and in y direction first and then
rotating 90 degree about the origin

B c

A
A) First Rotate by 90 degree and then translate with tx=ty=1
M = R(90) . T(1,1)
= Transformed triangle
=
C’

= A’
B’
Now apply this transformation on original points
P’ = P . M
= =
So the triangle after transformation is A’(1,2) , B’(0,1) , C’(0,2)
B) First translate with tx=ty=1 and then Rotate
Transformed triangle
M = T(1,1). R(90) .
=
C’ A’

= B’

=
Now apply this transformation on original points
P’ = P . M
= =
So the triangle after transformation is A’(-1,2) , B’(-2,1) , C’(-2,2)
 NOTE: Solve the same problem using theta = 45
HOME WORK

 Given a triangle A(10,10), B(20,20) and C(30,10) , scale the triangle by


keeping point A(10,10) as fixed with the scaling factors Sx = 1.5 and
Sy=1.5
Lets Take a Quiz

The transformation that is used to alter the size of the object is called
A) Translation
B) Rotation
C) Scaling
D) Reflection
E) All of the above
 To change the position of a circle we translate
1) Only center coordinate (i.e. origin)
2) center coordinate and redraw circle in a new location
3) each point on a circle.
4) All of these
 Positive value for the rotation angle θ defines
A) counter clockwise rotation of a point
B) Counter clock wise translation a point
C) clock wise rotation of a point
D) clockwise Translation of a point
 ____________ is a rigid body transformation that moves the object
without deformation
A) Rotation
B) Scaling
C) Transformation
D) All
 In geometric transformation
A) Object is moved while back ground is kept stationery or fixed.
B) Background is moved while object is kept stationary
C) Bothe object and Background are moved
D) all
 The translation distance (dx,dy) is called
1) Translation vector
2) Shift vector
3) Both (1) and ( 2 )
4) None
End of Chapter 3

You might also like