Upload
krishna-rana-magar
View
217
Download
0
Embed Size (px)
Citation preview
7/29/2019 transformation.doc
1/5
-axis
-axis
P
P
T
-axis
2D Transformations
Translation
Repositioning an object along a straight line path from one coordinate location to another
Add translational distance tx ,ty to original coordinate position (x,y) to move the point to a new position (x,y)x = x + tx y = y + ty
where the pair (tx , ty) is called the translation vector.
We can write equation as a single matrix equation by using column vectors to represent coordinate points and
translation vectors. i.e.P = x T = tx P = x
y ty y .so we can write
P = P + T
.Scaling
The transformation changes thesize of an object
Such that we can magnify or reduce its sizeIn case of polygons scaling is done by multiplying coordinate values (x,y) of each vertex by scaling factors sx sy
produce the final transformed coordinates (x,y).sx scales object in x directionsy scales object in y direction
or
P = x T = sx 0 P = xy 0 sy y
or
x sx 0 x
y = 0 sy . yor
P = S . P
Values greater than 1 for s x s y produce enlargementValues greater than 1 for s x s yreduce size of object
s x = s x = 1 leaves the size of the object unchanged
When s x, s y are assigned the same value s x = s x = 3 or 4 etc then a Uniform Scalingis produced.
Rotation
Repositioning an object along a circular path in x,y plane
Specify rotation angle and position (x r,y r) of rotation point about which the object is to be rotated+ value for define counter-clockwise rotation about a point
- value for define clockwise rotation about a point
If (x,y) is the original point r the constant distance from origin, the original angular displacement from x-
axis.Now the point (x,y) is rotated through angle in a counter clock wise direction
Express the transformed coordinates in terms of and asx = r cos( + ) = r cos. cos - r sin. sin .(i)
y = r sin( + ) = r cos. sin + r sin. cos .(ii)
We know that original coordinates of point in polar coordinates arex = r cos
y = r sin
substituting these values in (i) and (ii)
Anil Verma, IOE Pulchowk Page
rr
x
x
x -axis
x -axis
7/29/2019 transformation.doc
2/5
-axis
-axis
-axis
we get,
x = x cos - y sin
y = x sin + y cos
so using column vector representation for coordinate points the matrix form would beP = R . P
where the rotation matrix is
R = cos -sin
sin cos
Reflection
Generates a mirror image of the original object
(i).Reflection about x axis or about line y = 0
Keeps x value same but flips y value of coordinate pointsSo x = x
y = -yi.e.
x = 1 0 x
y 0 -1 y
(ii).Reflection about y axis or about line x = 0
Keeps y value same but flips x value of coordinate points
So x = -x
y = yi.e.
x = -1 0 x
y 0 1 y
(iii).Reflection about origin
Flip both x and y coordinates of a pointSo x = -x
y = -y
i.e.
x = -1 0 xy 0 -1 y
(iv).Reflection about line y = x
Steps required:i. Rotate about origin in clockwise direction by 45
degree which rotates line y = x to x-axisii. Take reflection against x-axis
iii. Rotate in anti-clockwise direction by same angle
here,R = cos sin R = cos -sin
-sin cos sin cos
For reflection against x-axis,
Anil Verma, IOE Pulchowk Page
x -axis
x -axis
x -axis
x -axis
7/29/2019 transformation.doc
3/5
-axis
-axis
Rf = 1 0
0 1
so for = 45 we get
R(y = x) = 0 11 0
(v).Reflection about line y = -x
Steps required:i. Rotate about origin in clockwise direction by 45
ii. Take reflection against y-axisiii. Rotate in anti-clockwise direction by same angle
here,
R = cos sin R = cos -sin
-sin cos sin cosFor reflection against x-axis,
Rf = 1 0
0 1so for = 45 we get
R(y = -x) = 0 -1-1 0
Shearing
Distorts the shape of object in either x or y or both direction
In case of single directional shearing (e.g. in x direction can be viewed as an object made up of very thin layer
and slid over each other with the base remaining where it is).
in x direction,
x = x + shx . yy = y
x = 1 shx x
y 0 1 . yin y direction,
x = x
y = y + shy . x
x = 1 0 xy shy 1 . y
in both directions,
x = x + shx . y
y = y + shy . xx = 1 shx x
y shy 1 . y
Homogenous CoordinatesThe matrix representations for translation, scaling and rotation are respectively:
P = T + P
P = S . P
Anil Verma, IOE Pulchowk Page
bi direction sheary direction shear
x direction shear
x -axis
x -axis
7/29/2019 transformation.doc
4/5
P = R . P
Translation is treated differently (as addition) from scaling and rotation (as multiplication)
We need to treat all three transformations in a consistent way so they can be combined easily.
Graphics applications involve sequence of geometric transformations. e.g. animation may require an object to betranslated , rotated etc in a sequence.
For an animation that requires scaling, rotation, translation, instead of applying each transformation one at a tim
separately we can combine them so that final coordinates are obtained directly from initial coordinates thus
eliminating intermediate steps.Here, incase of homogenous coordinates we add a third coordinate h to a point (x,y) so that each point is
represented by (hx, hy, h).h is normally set to 1.
If points are expressed in homogenous coordinates, all geometrical transformation equations can be represented
matrix multiplications.
Coordinates of a point are represented as three element column vectors, transformation operations are written asx 3 matrices.
So, for translation we have
x 1 0 tx xy = 0 1 ty . y
1 0 0 1 1or, P = T( tx , ty ) . PWith T( tx , ty ) as translation matrix, inverse of this translation matrix is obtained by representing tx, ty with -tx-ty.
Similarly, the rotation transformation equation about the coordinate origin arex cos -sin 0 x
y = sin cos 0 . y
1 0 0 1 1
or, P = R() . PHere, rotation operator R() is a 3 x 3 matrix and inverse rotation is obtained with .
Similarly, scaling relative to coordinate origin is
x shx 0 0 xy = 0 shy 0 . y
1 0 0 1 1
or, P = S( shx , shy ) . PInverse scaling matrix is obtained with 1 / shx and 1 / shx .Composite Transformation
With the matrix representation of transformation equations it is possible to setup a matrix for any sequence of
transformations as a composite transformation matrix by calculating the matrix product of individualtransformation.
For column matrix representation of coordinate positions we form composite transformation by multiplying
matrices in order from right to left.
i. Two Successive Translation are Additive
Let two successive translation vectors ( tx1 , ty1 ) and ( tx2 , ty2 ) are applied to a coordinate position P thenor, P = T( tx2 , ty2 ) . {T( tx1 , ty1 ) . P} and P = {T( tx2 , ty2 ) . T( tx1 , ty1 ) } . P
Here the composite transformation matrix for this sequence of translation is
1 0 tx2 1 0 tx1 1 0 tx1 + tx2
0 1 ty2 . 0 1 ty1 = 0 1 ty1+ ty2
0 0 1 0 0 1 0 0 1
Anil Verma, IOE Pulchowk Page
7/29/2019 transformation.doc
5/5
or, T( tx2 , ty2 ) . T( tx1 , ty1 ) = T( tx1 + tx2 , ty1 + ty2 )
ii. Two successive Scaling operations are MultiplicativeLet ( sx1 , sy1 ) and ( sx2 , sy2 ) be two successive vectors applied to a coordinate position P then the composite
scaling matrix thus produced is
or, P = S( sx2 , sy2 ) . {S( sx1 , sy1 ) . P} and P = {S( sx2 , sy2 ) . S( sx1 , sy1 ) } . P
Here the composite transformation matrix for this sequence of translation is
sx2 0 0 sx1 0 0 sx2 . sx1 0 00 sy2 0 . 0 sy1 0 = 0 sy2 . sy1 0
0 0 1 0 0 1 0 0 1
or, S( sx2 , sy2 ) . S( sx1 , sy1 ) = S( sx1 . sx2 , sy1 . sy2 )
iii. Two successive Rotation operations are Additive
Let R(1) and R(2) be two successive rotations applied to a coordinate position P then the composite scalingmatrix thus produced is
or, P = R(2) . {R(1) . P} and P = {R(2) . R(1) } . PHere the composite transformation matrix for this sequence of translation isor,
cos2 -sin2 cos 1 -sin 1
sin2 cos2 . sin 1 cos 1
or,
cos2 . cos1 - sin2 . sin1 -cos2 . sin1 - sin2 . cos1sin2 . cos1 + sin1 . cos2 . cos2 . cos1 - sin2 . sin1
or,
cos(2 + 2) -sin(2 + 2)
sin(2 + 2) . cos(2 + 2)
or, R(2) . R(1) = R(1 + 2)
Affine Transformation
Linear 2D geometric transformation which maps variables (e.g. pixel intensity values located at point (x1,y1) in a
input image) into new variables (e.g. (x2y2) in an output image) by applying a linear combination of translation,
rotation , scaling and/or shearing operations.
**NOTE:
- See class notes for pivot and fixed point transformations
- See class notes for reflection about arbitrary line (y = mx + c)
Anil Verma, IOE Pulchowk Page