0% found this document useful (0 votes)
21 views9 pages

Understanding 2D Transformations in Graphics

2D transformations change graphics by applying rules like translation, scaling, and rotation. Transformations are important in computer graphics to reposition and modify graphics on screen. Homogenous coordinates use 3D vectors instead of 2D to allow sequential transformations through matrix multiplication. Common 2D transformations include translation by adding a shift vector to coordinates, and rotation by applying trigonometric functions to original coordinates and rotating them by an angle.

Uploaded by

ASLAM KARJAGI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views9 pages

Understanding 2D Transformations in Graphics

2D transformations change graphics by applying rules like translation, scaling, and rotation. Transformations are important in computer graphics to reposition and modify graphics on screen. Homogenous coordinates use 3D vectors instead of 2D to allow sequential transformations through matrix multiplication. Common 2D transformations include translation by adding a shift vector to coordinates, and rotation by applying trigonometric functions to original coordinates and rotating them by an angle.

Uploaded by

ASLAM KARJAGI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2D Transformation

Transformation means changing some graphics into something else by applying rules. We
can have various types of transformations such as translation, scaling up or down, rotation,
shearing, etc. When a transformation takes place on a 2D plane, it is called 2D
transformation.

Transformations play an important role in computer graphics to reposition the graphics on


the screen and change their size or orientation.

Homogenous Coordinates
To perform a sequence of transformation such as translation followed by rotation and
scaling, we need to follow a sequential process −
Translate the coordinates,
Rotate the translated coordinates, and then
Scale the rotated coordinates to complete the composite transformation.
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra
dummy coordinate W.
In this way, we can represent the point by 3 numbers instead of 2 numbers, which is called
Homogenous Coordinate system. In this system, we can represent all the transformation
equations in matrix multiplication. Any Cartesian point P X
X,, Y
Y can be converted to

homogenous coordinates by P’ (Xh, Yh, h).

Translation
A translation moves an object to a different position on the screen. You can translate a point
in 2D by adding translation coordinate (tx, ty) to the original coordinate X
X,, Y
Y to get the

new coordinate X
′′
X ,, Y
Y
′′
.
From the above figure, you can write that −

X’ = X + tx
Y’ = Y + ty

The pair (tx, ty) is called the translation vector or shift vector. The above equations can also
be represented using the column vectors.
′′
[[X
X]] [[X
X ]] [[t
tx ]
x]
P
P =
= p' = ′′
T=
[[Y
Y ]] [[Y
Y ]] [[t
ty ]
y]

We can write it as −

P’ = P + T

Rotation
In rotation, we rotate the object at particular angle θ t
thhe
etta
a from its origin. From the

following figure, we can see that the point P X


X,, Y
Y is located at angle φ from the

horizontal X coordinate with distance r from the origin.


Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you
will get a new point P’ X
′′
X ,, Y
Y
′′
.
Using standard trigonometric the original coordinate of point P X
X,, Y
Y can be represented

as −

X
X =
= r
rcco
ossϕ
ϕ.. .. .. .. .. .. (
(11)
)

Y
Y =
= r
rssi
innϕ
ϕ.. .. .. .. .. .. (
(22)
)

Same way we can represent the point P’ X


′′
X ,, Y
Y
′′
as −

′′
x
x =
= r
rcco
oss (
(ϕϕ +
+ θ
θ)) =
= r
rcco
ossϕ
ϕcco
ossθ
θ −
− r
rssi
innϕ
ϕssi
innθ
θ.. .. .. .. .. .. .. (
(33)
)

′′
y
y =
= r
rssi
inn (
(ϕϕ +
+ θ
θ)) =
= r
rcco
ossϕ
ϕssi
innθ
θ +
+ r
rssi
innϕ
ϕcco
ossθ
θ.. .. .. .. .. .. .. (
(44)
)

Substituting equation 1
1 & 2
2 in 3
3 & 4
4 respectively, we will get

′′
x
x =
= x
xcco
ossθ
θ−− y
yssi
innθ
θ
′′
y
y =
= x
xssi
innθ
θ++ y
ycco
ossθ
θ

Representing the above equation in matrix form,

′′ ′′
c
coos
sθθ s
siin
nθθ
[[X
X Y
Y ]] =
= [[X
XYY ]] [
[ ]
]OOR
R

−ssi
innθ
θ c
coos
sθθ

P’ = P . R
Where R is the rotation matrix

c
coos
sθθ s
siin
nθθ
R
R =
= [
[ ]
]

−ssi
innθ
θ c
coos
sθθ

The rotation angle can be positive and negative.

For positive rotation angle, we can use the above rotation matrix. However, for negative
angle rotation, the matrix will change as shown below −

c
coos
s((−
−θθ)
) s
siin
n((−
−θθ)
)
R
R =
= [
[ ]
]

−ssi
inn(
(−−θ
θ)) c
coos
s((−
−θθ)
)

c
coos
sθθ −
−ssi
innθ
θ
=
= [
[ ]
]((∵
∵ c
coos
s((−
−θθ)
) =
= c
coos
sθθ a
annd
d s
siin
n((−
−θθ)
) =
= −
−ssi
innθ
θ))
s
siin
nθθ c
coos
sθθ

Scaling
To change the size of an object, scaling transformation is used. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the desired
result.

Let us assume that the original coordinates are X


X,, Y
Y , the scaling factors are (SX, SY),

and the produced coordinates are X


′′
X ,, Y
Y
′′
. This can be mathematically represented as
shown below −
X' = X . SX and Y' = Y . SY
The scaling factor SX, SY scales the object in X and Y direction respectively. The above
equations can also be represented in matrix form as below −

′′
X
X X
X S
Sxx
0
0
(
( )
) =
= (
( )
)[[ ]
]
′′
Y
Y Y
Y 00 S
Syy

OR

P’ = P . S
Where S is the scaling matrix. The scaling process is shown in the following figure.
If we provide values less than 1 to the scaling factor S, then we can reduce the size of the
object. If we provide values greater than 1, then we can increase the size of the object.

Reflection
Reflection is the mirror image of original object. In other words, we can say that it is a
rotation operation with 180°. In reflection transformation, the size of the object does not
change.

The following figures show reflections with respect to X and Y axes, and about the origin
respectively.
Shear
A transformation that slants the shape of an object is called the shear transformation. There
are two shear transformations X-Shear and Y-Shear. One shifts X coordinates values and
other shifts Y coordinate values. However; in both the cases only one coordinate changes
its coordinates and other preserves its values. Shearing is also termed as Skewing.

X-Shear
The X-Shear preserves the Y coordinate and changes are made to X coordinates, which
causes the vertical lines to tilt right or left as shown in below figure.

The transformation matrix for X-Shear can be represented as −


1
1 s
shhx
x 0
0

⎡ ⎤

X
Xssh
= ⎢0
h = ⎢ 0 1
1 0
0⎥⎥

⎣ ⎦

0
0 0
0 1
1

Y' = Y + Shy . X

X’ = X

Y-Shear
The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the
horizontal lines to transform into lines which slopes up or down as shown in the following
figure.

The Y-Shear can be represented in matrix from as −

1
1 0
0 0
0

⎡ ⎤

Y
Ys h ⎢
sh ⎢ssh
hyy 1
1 0
0⎥⎥

⎣ ⎦

0
0 0
0 1
1

X’ = X + Shx . Y

Y’ = Y

Composite Transformation
If a transformation of the plane T1 is followed by a second plane transformation T2, then the
result itself may be represented by a single transformation T which is the composition of T1
and T2 taken in that order. This is written as T = T1∙T2.

Composite transformation can be achieved by concatenation of transformation matrices to


obtain a combined transformation matrix.
A combined matrix −

[T][X] = [X] [T1] [T2] [T3] [T4] …. [Tn]


Where [Ti] is any combination of

Translation
Scaling
Shearing
Rotation
Reflection
The change in the order of transformation would lead to different results, as in general
matrix multiplication is not cumulative, that is [A] . [B] ≠ [B] . [A] and the order of
multiplication. The basic purpose of composing transformations is to gain efficiency by
applying a single composed transformation to a point, rather than applying a series of
transformation, one after another.

For example, to rotate an object about an arbitrary point (Xp, Yp), we have to carry out three
steps −
Translate point (Xp, Yp) to the origin.
Rotate it about the origin.
Finally, translate the center of rotation back where it belonged.

Common questions

Powered by AI

The purpose of performing a sequence of transformation operations, such as translation followed by rotation and scaling, is to achieve specific repositioning and resizing effects on a 2D object. Matrix concatenation facilitates this process by allowing multiple transformations to be combined into a single composite matrix. This approach streamlines operations, minimizes computational steps, and ensures consistent results by applying a unified transformation to produce the desired effect .

Reflection in 2D transformations is mathematically performed by transforming the object's coordinates using a reflection matrix that essentially rotates the object 180° about the axis of reflection. Unlike other transformations like scaling, reflection does not alter the object's size. It merely reverses the direction of axes, creating a mirrored image along specified axes (X or Y) or about the origin .

In a 2D scaling transformation, the scaling factor determines whether the object expands or contracts. A factor greater than 1 enlarges the object, whereas a factor less than 1 shrinks it. The operation is performed using a scaling matrix [S_x, 0; 0, S_y], where S_x and S_y are the scaling factors along the X and Y axes, respectively. This matrix is multiplied with the point's coordinate matrix to achieve the desired size modification .

The translation vector moves an object to a different location on a 2D plane without altering its orientation or scale. It is mathematically represented by adding the translation vector (t_x, t_y) to the original coordinates (X, Y), resulting in new coordinates (X + t_x, Y + t_y). This operation can also be represented in matrix form as a simple addition to the coordinate matrix .

In 2D graphics, the order of composite transformations is crucial because matrix multiplication is not commutative; this means the order of applied transformations T1, T2, etc., affects the final outcome. For instance, translating an object before rotating will yield different results compared to rotating before translating. This property allows for precise control over the transformation sequence to achieve a desired visual effect .

The additional dummy coordinate in homogeneous coordinates enables the representation of 2D transformations in a 3D space, which simplifies calculations, particularly when combining multiple transformations through matrix multiplication. This coordinate is typically represented by the variable 'h' and allows for the conversion of 2D matrices into 3x3 matrices, enabling all transformations to be expressed as matrix operations .

By using a homogeneous coordinate system, 2D transformations can be efficiently combined into a single operation using matrix multiplication. Transformations such as translation, rotation, and scaling can be represented as 3x3 matrices, which allows sequential transformations to be combined into one matrix through matrix multiplication. This simplifies the process as any Cartesian point can be transformed using a composite transformation matrix without manually applying each transformation one at a time .

For rotation in a 2D plane, the transformation matrix varies with the direction of rotation. With a positive rotation angle, the matrix has cos(θ) and sin(θ) in positions that result in counter-clockwise rotation. For a negative rotation angle, the sine elements are negated, which flips the direction of rotation to clockwise. The specific matrix form for a positive angle includes elements [cos(θ), -sin(θ); sin(θ), cos(θ)], while for a negative angle, it becomes [cos(θ), sin(θ); -sin(θ), cos(θ)].

Performing multiple transformations sequentially can result in complex calculations and potential errors if the order is not carefully managed. Matrix multiplication is not commutative, meaning the order of operations affects the final result. This challenge is addressed by using composite transformation matrices that combine sequential transformations into a single matrix operation, reducing complexity and on-the-fly recalibration needs .

A shear transformation slants the shape of an object, resulting in a skewed appearance. This can be represented by matrix forms known as X-Shear and Y-Shear. For X-Shear, the transformation matrix is [1, Sh_x; 0, 1], applying to X coordinates while keeping Y constant. Conversely, Y-Shear uses a matrix [1, 0; Sh_y, 1], altering Y and preserving X. These transformations effectively tilt lines within the object while retaining one axis' coordinates .

You might also like