Transformation
Transformation
change one visual into another. Lines, rectangles, circles, and triangles can occasionally
be combined to create an image or picture. It ought to be necessary to alter these
pictures if we sketch the fundamental and combination pictures.
The following operations may now be carried out to alter the images:
An image's location can be altered.
An image's size is something we can change.
The image's angle is modifiable.
We will find a new picture by applying the aforementioned activities; this procedure is
known as transformation. Certain algorithms allow us to create new images.
§ - –
Tx 1 0 Tx Sx Sx 0 0
Ty = 0 1 Ty Sy = 0 Sy 0
0 0 1 0 0 1
Clockwise Anti-Clockwise
– –
1 0 1 0 0 -1 0 -1 0 0 -1 0 -1 0 0
0 -1 0 -1 0 0 1 0 1 0 0 -1 0 -1 0
0 0 1 0 0 1 0 0 1
= =–
0 1 0 1 0 0 -1 0 -1 0
1 0 1 0 0 -1 0 -1 0 0
0 0 1 0 0 1
– –
1 0 1 0 0 1 shy 1 shy 0
Shx 1 shx 1 0 0 1 0 1 0
0 0 1 0 0 1
Basic type of 2D transformation are-
1. 2D Translation: "Translation is a method used to shift the entity on the monitor from one
location to another location."
2. 2D Rotation: "Rotation is a technique used to twist an entity from its source to a certain angle. "
3. 2D Scaling: "Scaling is a form or method used in a two-dimensional plane to resize the entity. "
4. 2D Reflection: "Reflection is a phase or system through which the entity can be rotated at a
180 ° angle."
5. 2D Shearing: "Shearing is a technique that is used to conduct the entity's slanting." It is often
referred to as "Skewing."
Translation of a point
Here we only translate the x and y coordinates of given
point as per given translation factor dx and dy respectively. We get final coordinate
(after translation) if we add translation factor with original coordinate respectively.
The translation of a line is to translate both the end points of
the line by the given translation factor (fx, fy) and then redraw the line between the
new end points (original end points + translation factor respectively) depends on
the display device used and line drawing algorithm followed:
x'=x+fx y'=y+fy
Consider a line with two end points A(0, 8) and B(9, 12). Also given translation
factor (fx, fy) is (6, -3).
Here, A(0, 8) and implying fx= 6, fy= –3. Now A'=(0+6, 8+(–3))
A'=(6, 5)
B(9, 12) and implying fx= 6, fy= –3. Now B'=(9+6, 12+(–3))
B'=(15, 9)
Or, we can say–
X1' 0 6 6
Y1' = 8 + -3 = 5
and X2' 9 6 15
Y 2' = 12 + -3 = 9
: The length and slope of the translated line remains same as that of the
original line.
Here we only translate the x and y coordinates of given
circle centre as per given translation factor fx and fy respectively. We get final circle
centre coordinate (after translation) if we add translation factor with original centre
coordinate respectively.
Given a circle with radius 10 and centre coordinate (1, 4). Apply translation with
diance 5 towards x-axis and 1 towards y-axis. Obtain the new coordinates of the
circle without changing the radius.
Translation of rectangle
The Translate function handles the translation of the
rectangle. It takes the current position (x, y) of the rectangle and the height and width
as input. The user is prompted to enter the translation coordinates (fx, fy). The function
then clears the screen using the clear device() and calculates the rectangle's new position
(x', y') after translation by adding the translation coordinates to the initial position.
Finally, it calls the Rectangle function to draw the translated rectangle.
Given a rectangle with coordinate points A(0,3), B(3,3), C(3,0), D(0,0). Apply the
translation with diance 1 towards x-axis and 1 towards y-axis. Obtain the new
coordinates of the square.
Similarly, new co-ordinate of corner C' and D' are (4, 1) and (1, 1) respectively.
In rotation, we rotate the object at particular angle ϴ
from its origin. Rotation can be clockwise or anti-clockwise. For rotation, we have to
specify only the angle of rotation or the angle of rotation and rotation point/pivot
point.
or, x'=rcos(ϴ+φ)
= r.cosϴ.cosφ – r.sinϴ.sinφ
or, x'=x.cosφ – y.sinφ
sin(ϴ+φ) =
clockwise
, (-ve).
Rotate line AB whose endpoints are A (2, 5) and B (6, 12) about origin thugh a
30° clockwise direction.
.866 -0.5
= 2 5 * .5 .866
= 1.732+2.5 -1+4.33
= 4.232 3.33
.866 -0.5
= 6 12 * .5 .866
= 5.196+6 -3+10.392
= 11.196 7.392
Consider the point P(x,y) is located at angle φ from the horizontal x coordinate with
distance r from the arbitrary point.
Suppose we want to rotate it at the angle ϴ. After rotating it to a new location P'(x',y').
Here arbitrary point locate at location s(xp,yp).
Calculate x' = OB
= OA+AB
= xp+(x–xp)cosθ –(y–yp)sinθ
= xp+xcosθ –xpcosθ –ysinθ +ypsinθ
= {(1–cosθ)xp +ypsinθ}+{xcosθ–ysinθ}
/ = φ / = (θ+φ)
Calculate y' = OB' = . φ = (θ+φ)
= OA'+A'B' ( – ) = . φ = . φ θ
= yp+(x–xp)sinθ +(y-yp)cosθ –. φ θ
' '/ = φ =( – ) θ
= yp +xsinθ –xpsinθ +ycosθ -ypcosθ
' '= φ –( – ) θ
= {(1–cosθ)yp –xpsinθ}+{xsinθ+ycosθ} ( – )= φ
A transformation sequence for rotating an object about a specified pivot point using
the rotation matrix, x' (1–cosθ) sinθ xp cosθ –sinθ x
y' = –sinθ (1-cosθ) yp
* *
sinθ cosθ + y
Scaling is a process of
modifying or changing the size of objects. It is type of
transformation through which we can zoom-in or zoom-
out any particular object or shape.
Consider a square with coordinate P(1,4), Q(4,4), R(4,1), T(1,1). Apply scaling factor
3 on x-axis and 4 on the y-axis. Find out new coordinate of the square.
––
x' sx 0 x 1-sx 0 xf
y'
= 0 sy y
+
0 1-sy yf
- ––
Scaling with respect to an arbitrary point so, we can first translate arbitrary point
to the origin and then scaling at last translate to given arbitrary point.
x' 1 0 xf Sx 0 0 1 0 -xf x
y' = 0 1 yf 0 Sy 0 0 1 -yf y
1 0 0 1 0 0 1 0 0 1 1
Translation (origin to given
arbitrary point) Matrix
1 0 xf Sx 0 0 x-xf
= 0 1 yf 0 Sy 0 y-yf
0 0 1 0 0 1 1
1 0 xf Sx(x-xf) Sx(x-xf)+xf
= 0 1 yf Sy(y-yf) = Sy(y-yf)+ yf
0 1 1 1 1
So, x'= Sx(x-xf)+xf = Sx.x -Sx.xf +xf = sx.x+(1-sx)xf
y'= Sy(y-yf)+ yf = Sy.y -Sy.yf +yf = sy.y+(1-sy)yf
The Reflection is a mirror image of the original object. In
the Reflection process, the size of the object does not change.
or
Reflection is a kind of rotation where the angle of rotation is 180°.
The reflected object is always formed on the other side of mirror.
The size of reflected object is same as the size of original object.
x' -1 0 x
y' = 0 1 * y
3. Reflection along with the line Y=X:
In this kind of Reflection, the value of X is
equal to the value of Y. We can represent the Reflection
along y-axis by following equation-
Y=X, then the points are (Y, X)
& x'=y, y'=x
We can also represent Reflection in the form of matrix-
x' 0 1 x
y'
= 1 0 * y
x' -1 0 x
y' = 0 -1 * y
Shearing basically a technique which changes the shape
of existing object in a two-dimensional plane. In a two-dimensional plane, the object
size can be changed along X direction as well as Y direction.
The term scaling facto r is used to define whether the size of the object is increased
or decreased. We can represent the scaling factor by ‘Sx’ for the x-axis, ‘Sy’ for the y-
axis, and ‘Sz’ for the z-axis.
The increment and decrement of an object is depending on two conditions. They are-
If scaling factor (Sx, Sy, Sz) > 1, then the size of the object increased.
If scaling factor (Sx, Sy, Sz) < 1, then the size of the object decreased.
≠ ≠
Scaling with respect to any arbitrary point
Scaling with respect to an arbitrary
fixed point is not as simple as scaling with respect to the origin. The procedure of
scaling with respect to an arbitrary point is:
Translate the object so that the fixed point coincides with the origin.
Scale the object with respect to the origin.
Use the inverse translation of step 1 to return the objects to its original
position.
Consider a point P(x, y, z) of a object scaled relative to a fixed point(x f, yf, zf) can be
achieved by using the following equation––
x'=Sx.x +(1-Sx)xf
Translate origin to x'=Sy.y +(1-Sy)yf
Arbitrary point z'=Sz.z +(1-Sz)zf
In matrix representation with homogeneous co-ordinates of above equation–
x' 1 0 0 tx Sx 0 0 0 1 0 0 -tx x
y' 0 1 0 ty * 0 Sy 0 0 0 1 0 -ty * y
= *
z' 0 0 1 tz 0 0 Sz 0 0 0 1 -tz z
1 0 0 0 1 0 0 0 1 0 0 0 1 1
x' Sx 0 0 -Sx.tx+tx x
y' 0 Sy 0 -Sy.ty+ty * y
z' = 0 0 Sz -Sz.tz+tz z
1 0 0 0 1 1
x' Sx 0 0 (1-Sx)xf x
y' = 0 Sy 0 (1-Sy)yf * y
z' 0 0 Sz (1-Sz)zf z
1 0 0 0 1 1
In general, rotations are specified by a rotation axis and an
angle. In two-dimensions there is only one choice of a rotation axis that leaves points
in the plane.
The easiest rotation axes are those that parallel to the coordinate axis.
Positive rotation angles produce counterclockwise rotations about a coordinate
axis, if we are looking along the positive half of the axis toward the coordinate
origin.
For example, let us assume, the initial co-ordinate of an object is (x, y, z), the
initial angle of the object with respect to origin is φ and
θ. The new co-ordinate aer rotation is (x', y', z').
Rotation about principal Axis We can rotate an object parallel or along to the specific
axis so that the co-ordinate about which the object rotates, remains unchanged and the
rest two of the co-ordinates get changes.
There are three kinds of such rotations that are possible–––
Here object rotate parallel to the x-axis, so x-coordinate remains unchanged and
rest two co-ordinate y and z only change.
The rotation is achieved by using the following equations –––
x'=x
y'=ycosθ–zsinθ
z'=ysinθ+zcosθ
Matrix representation of above equations is given as follows––
x' 1 0 0 x
y' = 0 cosθ -sinθ * y
z' 0 sinθ cosθ z
Rn abt y ax
Here object rotate parallel to the y-axis, so y-coordinate remains unchanged and
rest two co-ordinate x and z only change.
The rotation is achieved by using the following equations –––
x'=zsinθ+xcosθ
y'=y
z'=zcosθ-xsinθ
Matrix representation of above equations is given as follows––
Here object rotate parallel to the z-axis, so z-coordinate remains unchanged and
rest two co-ordinate x and y only change.
The rotation is achieved by using the following equations –––
x'=xcosθ-ysinθ
y'=xsinθ+ycosθ
z'=z
Consider a point P(x, y, z) in 3D plane, aer reflection the new co-ordinate of the
P is P'(x', y', z').
In the xy plane, after reflection the object goes on opposite side of the xy
plane along the z direction. In simple word when xy plane reflection, then value
of z is negative.
This reflection is achieved by using the following reflection equations––
x'=x
y'=y
z'=–z
x' 1 0 0 x
y' = 0 1 0 * y
z' 0 0 -1 z
Matrix representation of above equations using homogeneous co-ordinate is given as
follows–
x' 1 0 0 0 x
y' = 0 1 0 0 * y
z' 0 0 -1 0 z
1 0 0 0 1 1
Refn to YZ p
In the yz plane, after reflection the object goes on opposite side of the yz
plane along the x direction. In simple word when yz plane reflection, then value
of x is negative.
This reflection is achieved by using the following reflection equations––
x'=–x
y'=y
z'=z
x' -1 0 0 x
y' = 0 1 0 * y
z' 0 0 1 z
Matrix representation of above equations using homogeneous co-ordinate is given as
follows– x' -1 0 0 0 x
y' 0 1 0 0 y
=
z' 0 0 1 0 * z
1 0 0 0 1 1
In the xz plane, after reflection the object goes on opposite side of the xz
plane along the y direction. In simple word when xz plane reflection, then value
of y is negative.
This reflection is achieved by using the following reflection equations––
x'=x
y'=–y
z'=z
Consider a point P with co-ordinates (x, y, z) and Shx, Shy and Shz are the shearing
parameters toward x, y and z-axis respectively and also new point P'(x', y', z').
Sg X n
In this, we can store the x coordinate and only change the y and z coordinate.
x'= x
y'= y+Shy.x
z'= z+Shz.x
x'= x+Shx.y
y'= y
z'= z+Shz.y
Sg Z n
In this, we can store the z coordinate and only change the x and y coordinate.
x'= x+Shx.z
y'= y+Shy.z
z'= z