UNIT -3
Geometrical Transformation
Transformation in Computer Graphics is utilized to modify the
position, orientation, or size of objects within a graphical scene. By
employing mathematical operations, vertices or points in a 3D or 2D
space are manipulated to achieve the desired changes.
2d Transformation in Computer Graphics
2d Transformation in Computer Graphics is utilized to modify the
position, orientation, or size of objects within a two-dimensional
space. These transformations involve applying mathematical
operations to the coordinates of points or vertices in order to achieve
the desired changes.
These transformations can be applied in a sequence to achieve more
complex effects. For example, a combination of translation, rotation,
and scaling operations can be used to animate an object’s
movement, rotation, and resizing in a 2D animation.
The various 2d Transformation in Computer Graphics
examples include object manipulation, computer-aided design (CAD),
image processing, and graphical user interfaces (GUIs). By
manipulating the position, orientation, and size of objects within a
2D space, these transformations enable a wide range of visual effects
and graphical applications.
The fundamental geometrical 2d Transformation in Computer
Graphics include:
[Link]
[Link]
[Link]
Translation :
2D Translation is a transformation technique that changes the
position of each point in an object or a coordinate system by a
specified distance in the x and y
axes.
Applying 2D translation, we can say:
X’ = X + tx
Y’ = Y + ty
(tx, ty) represents the shift or the translation vector. The equations
can be expressed using column vectors for efficient representation
and computation.
P=[X]/[Y] p’ = [X′]/[Y′] T = [tx]/[ty]
This can also be written as:
P’ = P + T
PRACTICE PROBLEMS BASED ON 2D TRANSLATION IN COMPUTER
GRAPHICS-
Problem-01:
Given a circle C with radius 10 and center coordinates (1, 4). Apply
the translation with distance 5 towards X axis and 1 towards Y axis.
Obtain the new coordinates of C without changing its radius.
Solution-
Given-
• Old center coordinates of C = (Xold, Yold) = (1, 4)
• Translation vector = (Tx, Ty) = (5, 1)
Let the new center coordinates of C = (Xnew, Ynew).
Applying the translation equations, we have-
• Xnew = Xold + Tx = 1 + 5 = 6
• Ynew = Yold + Ty = 4 + 1 = 5
Thus, New center coordinates of C = (6, 5).
Alternatively,
In matrix form, the new center coordinates of C after translation may
be obtained as-
Thus, New center coordinates of C = (6, 5).
Problem-02:
Given a square with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0).
Apply the translation with distance 1 towards X axis and 1 towards Y
axis. Obtain the new coordinates of the square.
Solution-
Given-
• Old coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
• Translation vector = (Tx, Ty) = (1, 1)
For Coordinates A(0, 3)
Let the new coordinates of corner A = (Xnew, Ynew).
Applying the translation equations, we have-
• Xnew = Xold + Tx = 0 + 1 = 1
• Ynew = Yold + Ty = 3 + 1 = 4
Thus, New coordinates of corner A = (1, 4).
For Coordinates B(3, 3)
Let the new coordinates of corner B = (Xnew, Ynew).
Applying the translation equations, we have-
• Xnew = Xold + Tx = 3 + 1 = 4
• Ynew = Yold + Ty = 3 + 1 = 4
Thus, New coordinates of corner B = (4, 4).
For Coordinates C(3, 0)
Let the new coordinates of corner C = (Xnew, Ynew).
Applying the translation equations, we have-
• Xnew = Xold + Tx = 3 + 1 = 4
• Ynew = Yold + Ty = 0 + 1 = 1
Thus, New coordinates of corner C = (4, 1).
For Coordinates D(0, 0)
Let the new coordinates of corner D = (Xnew, Ynew).
Applying the translation equations, we have-
• Xnew = Xold + Tx = 0 + 1 = 1
• Ynew = Yold + Ty = 0 + 1 = 1
Thus, New coordinates of corner D = (1, 1).
Thus, New coordinates of the square = A (1, 4), B(4, 4), C(4, 1), D(1,
1).
Rotation
In Computer graphics, 2D Rotation is a process of rotating an object
with respect to an angle or along a circular path in a two dimensional
plane.
Consider a point object O has to be rotated from one angle to
another in a 2D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold)
• Initial angle of the object O with respect to origin = Φ
• Rotation angle = θ
• New coordinates of the object O after rotation = (Xnew, Ynew)
This rotation is achieved by using the following rotation equations-
• Xnew = Xold x cosθ – Yold x sinθ
• Ynew = Xold x sinθ + Yold x cosθ
In Matrix form, the above rotation equations may be represented as-
PRACTICE PROBLEMS BASED ON 2D ROTATION IN COMPUTER
GRAPHICS-
Problem-01:
Given a line segment with starting point as (0, 0) and ending point as
(4, 4). Apply 30 degree rotation anticlockwise direction on the line
segment and find out the new coordinates of the line.
Solution-
We rotate a straight line by its end points with the same angle. Then,
we re-draw a line between the new end points.
Given-
• Old ending coordinates of the line = (Xold, Yold) = (4, 4)
• Rotation angle = θ = 30º
Let new ending coordinates of the line after rotation = (Xnew, Ynew).
Applying the rotation equations, we have-
Xnew
= Xold x cosθ – Yold x sinθ
= 4 x cos30º – 4 x sin30º
= 4 x (√3 / 2) – 4 x (1 / 2)
= 2√3 – 2
= 2(√3 – 1)
= 2(1.73 – 1)
= 1.46
Ynew
= Xold x sinθ + Yold x cosθ
= 4 x sin30º + 4 x cos30º
= 4 x (1 / 2) + 4 x (√3 / 2)
= 2 + 2√3
= 2(1 + √3)
= 2(1 + 1.73)
= 5.46
Thus, New ending coordinates of the line after rotation = (1.46,
5.46).
Alternatively,
In matrix form, the new ending coordinates of the line after rotation
may be obtained as-
Thus, New ending coordinates of the line after rotation = (1.46,
5.46).
Scaling:
• Scaling may be used to increase or reduce the size of object.
• Scaling subjects the coordinate points of the original object to
change.
• Scaling factor determines whether the object size is to be
increased or reduced.
• If scaling factor > 1, then the object size is increased.
• If scaling factor < 1, then the object size is reduced.
Consider a point object O has to be scaled in a 2D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold)
• Scaling factor for X-axis = Sx
• Scaling factor for Y-axis = Sy
• New coordinates of the object O after scaling = (Xnew, Ynew)
This scaling is achieved by using the following scaling equations-
• Xnew = Xold x Sx
• Ynew = Yold x Sy
In Matrix form, the above scaling equations may be represented as-
PRACTICE PROBLEMS BASED ON 2D SCALING IN COMPUTER
GRAPHICS-
Problem-01:
Given a square object with coordinate points A(0, 3), B(3, 3), C(3, 0),
D(0, 0). Apply the scaling parameter 2 towards X axis and 3 towards Y
axis and obtain the new coordinates of the object.
Solution-
Given-
• Old corner coordinates of the square = A (0, 3), B(3, 3), C(3, 0),
D(0, 0)
• Scaling factor along X axis = 2
• Scaling factor along Y axis = 3
For Coordinates A(0, 3)
Let the new coordinates of corner A after scaling = (Xnew, Ynew).
Applying the scaling equations, we have-
• Xnew = Xold x Sx = 0 x 2 = 0
• Ynew = Yold x Sy = 3 x 3 = 9
Thus, New coordinates of corner A after scaling = (0, 9).
For Coordinates B(3, 3)
Let the new coordinates of corner B after scaling = (Xnew, Ynew).
Applying the scaling equations, we have-
• Xnew = Xold x Sx = 3 x 2 = 6
• Ynew = Yold x Sy = 3 x 3 = 9
Thus, New coordinates of corner B after scaling = (6, 9).
For Coordinates C(3, 0)
Let the new coordinates of corner C after scaling = (Xnew, Ynew).
Applying the scaling equations, we have-
• Xnew = Xold x Sx = 3 x 2 = 6
• Ynew = Yold x Sy = 0 x 3 = 0
Thus, New coordinates of corner C after scaling = (6, 0).
For Coordinates D(0, 0)
Let the new coordinates of corner D after scaling = (Xnew, Ynew).
Applying the scaling equations, we have-
• Xnew = Xold x Sx = 0 x 2 = 0
• Ynew = Yold x Sy = 0 x 3 = 0
Thus, New coordinates of corner D after scaling = (0, 0).
Thus, New coordinates of the square after scaling = A (0, 9), B(6, 9),
C(6, 0), D(0, 0).
Introduction to Homogeneous Coordinates
In computer graphics and geometric modeling, transformations such
as translation, rotation, and scaling are commonly used. While
rotation and scaling can be expressed using matrix multiplication in
2D Cartesian coordinates, translation cannot. To overcome this, we
use homogeneous coordinates, which enable all affine
transformations to be represented uniformly using matrix
multiplication. Using homogeneous coordinates, we can combine
multiple transformations (like translation, rotation, and scaling) into
a single matrix. Homogeneous coordinates make it possible to use
matrix math for all transformations, making graphics calculations
more powerful, faster, and easier
In 2D, a point (x,y)(x, y)(x,y) in Cartesian coordinates can be
represented in homogeneous coordinates as:
(X,Y)=>(X,Y,1)
Basic 2D Transformations Using Homogeneous
Translation: Homogeneous coordinates allow us to represent
translation as a matrix multiplication, which isn't possible in regular
Cartesian coordinates.
To represent a 2D point (x,y)(x, y)(x,y) in homogeneous coordinates,
we write it as:
Composite 2D Transformations
Due to representations in homogeneous coordinates, a series of
transformations can be simply represented as matrix multiplications,
a composite is then obtained. The composite can then be used to
compute final coordinates straight away given the initial coordinates.
We can summarize the above steps in notation form as given below
P’= {R(90°).S(2,2)}.{P}
Step-1: Scaling w.r.t. fixed point – (2,2).
For this you can refer to the composite matrix discussed on ‘general
fixed point scaling’ section, and we have
If you could not remember this, follow the three steps
i.e. translate the fixed point, scale with respect to origin
and translate back. The composite matrix can be obtained as shown
below.
Step-2:Rotate by 90° CCW
In this step, if the question does not explicitly mention any pivot
point for performing transformation, we can safely assume origin as
the pivot point.(Otherwise if the question has information on a pivot
point about which the transformation is to be performed, then treat
this as complex and compute the composite matrix separately as
similar to that done in step-1). So we can assume the standard
homogeneous matrix representation for rotation as shown below
with angle 90°and CCW (counter Clock-Wise)rotations are positive.
Thus the final composite matrix is obtained by multiplying the two
matrices derived, as shown below.
Now multiply each vertex with the composite matrix and straight
away get the new vertex.
The new vertices are given below.
(2,2) -> (-2,2)
(2,10) -> (-18,2)
(10,2) -> (-2,18)
Introduction to 3-D Transformation
3-D Transformation is the process of manipulating the view of a
three-D object with respect to its original position by modifying its
physical attributes through various methods of transformation like
Translation, Scaling, Rotation.
Translation
It is the movement of an object from one position to another
position. Translation is done using translation vectors. There are
three vectors in 3D instead of two. These vectors are in x, y, and z
directions. Translation in the x-direction is represented using Tx. The
translation is y-direction is represented using Ty. The translation in
the z- direction is represented using Tz.
If P is a point having co-ordinates in three directions (x, y, z) is
translated, then after translation its coordinates will be (x1 y1 z1) after
translation. Tx Ty Tz are translation vectors in x, y, and z directions
respectively.
x1=x+ Tx
y1=y+Ty
z1=z+ Tz
Three-dimensional transformations are performed by transforming
each vertex of the object. If an object has five corners, then the
translation will be accomplished by translating all five points to new
locations. Following figure 1 shows the translation of point figure 2
shows the translation of the cube.
Matrix for translation
Matrix representation of point translation
Point shown in fig is (x, y, z). It become (x1,y1,z1) after translation.
Tx Ty Tz are translation vector.
Example: A point has coordinates in the x, y, z direction i.e., (5, 6, 7).
The translation is done in the x-direction by 3 coordinate and y
direction. Three coordinates and in the z- direction by two
coordinates. Shift the object. Find coordinates of the new position.
Solution: Co-ordinate of the point are (5, 6, 7)
Translation vector in x direction = 3
Translation vector in y direction = 3
Translation vector in z direction = 2
Translation matrix is
Multiply co-ordinates of point with translation matrix
= [5+0+0+30+6+0+30+0+7+20+0+0+1] = [8 9 9 1]
x becomes x1=8
y becomes y1=9
z becomes z1=9
Rotation
It is moving of an object about an angle. Movement can be
anticlockwise or clockwise. 3D rotation is complex as compared to
the 2D rotation. For 2D we describe the angle of rotation, but for a
3D angle of rotation and axis of rotation are required. The axis can be
either x or y or z.
There are three kinds of arbitrary rotation, here we can rotate an
object just parallel(or along) a specific axis so that the coordinate
about which the object rotates, remains unchanged and the rest two
of the coordinates get changes. There are three kinds of such
rotations that are possible:
• Rotation about the X-axis,
• Rotation about the Y-axis,
• Rotation about the Z-axis.
1) Rotation about the x-axis: In this kind of rotation, the object is
rotated parallel to the x-axis (principal axis), where
the x coordinate remains unchanged and the rest of the two
coordinates y and z only change. Consider a point with initial
coordinate P(x,y,z) in 3D space is made to rotate parallel to
the principal axis(x-axis). The coordinate position would change to
P'(x,y,z).
A rotation transformation matrix is used to calculate the new
position coordinate P’, which shown as below:
Rotation about the y-axis: In this kind of rotation, the object is
rotated parallel to the y-axis (principal axis), where the y coordinate
remains unchanged and the rest of the two coordinates x and z only
change
.
Rotation about the z-axis: In this kind of rotation, the object is
rotated parallel to the z-axis (principal axis), where the z coordinate
remains unchanged and the rest of the two coordinates x and y only
change.
Problem-01:
Given a homogeneous point (1, 2, 3). Apply rotation 90 degree
towards X, Y and Z axis and find out the new coordinate points.
Solution
Given-
• Old coordinates = (Xold, Yold, Zold) = (1, 2, 3)
• Rotation angle = θ = 90º
For X-Axis Rotation-
Let the new coordinates after rotation = (Xnew, Ynew, Znew).
Applying the rotation equations, we have-
• Xnew = Xold = 1
• Ynew = Yold x cosθ – Zold x sinθ = 2 x cos90° – 3 x sin90° = 2 x 0 – 3
x 1 = -3
• Znew = Yold x sinθ + Zold x cosθ = 2 x sin90° + 3 x cos90° = 2 x 1 + 3
x0=2
Thus, New coordinates after rotation = (1, -3, 2).
For Y-Axis Rotation-
Let the new coordinates after rotation = (Xnew, Ynew, Znew).
Applying the rotation equations, we have-
• Xnew = Zold x sinθ + Xold x cosθ = 3 x sin90° + 1 x cos90° = 3 x 1 + 1
x0=3
• Ynew = Yold = 2
• Znew = Yold x cosθ – Xold x sinθ = 2 x cos90° – 1 x sin90° = 2 x 0 – 1
x 1 = -1
Thus, New coordinates after rotation = (3, 2, -1).
For Z-Axis Rotation-
Let the new coordinates after rotation = (Xnew, Ynew, Znew).
Applying the rotation equations, we have-
Xnew = Xold x cosθ – Yold x sinθ = 1 x cos90° – 2 x sin90° = 1 x 0 – 2 x 1 =
-2
• Ynew = Xold x sinθ + Yold x cosθ = 1 x sin90° + 2 x cos90° = 1 x 1 + 2
x0=1
• Znew = Zold = 3
Thus, New coordinates after rotation = (-2, 1, 3).
Scaling
• Scaling may be used to increase or reduce the size of object.
• Scaling subjects the coordinate points of the original object to
change.
• Scaling factor determines whether the object size is to be
increased or reduced.
• If scaling factor > 1, then the object size is increased.
• If scaling factor < 1, then the object size is reduced.
Consider a point object O has to be scaled in a 3D plane.
Let-
• Initial coordinates of the object O = (Xold, Yold,Zold)
• Scaling factor for X-axis = Sx
• Scaling factor for Y-axis = Sy
• Scaling factor for Z-axis = Sz
• New coordinates of the object O after scaling = (Xnew, Ynew, Znew)
This scaling is achieved by using the following scaling equations-
• Xnew = Xold x Sx
• Ynew = Yold x Sy
• Znew = Zold x Sz
• In Matrix form, the above scaling equations may be represented
as-
PRACTICE PROBLEMS BASED ON 3D SCALING IN COMPUTER
GRAPHICS-
Problem-01:
Given a 3D object with coordinate points A(0, 3, 3), B(3, 3, 6), C(3, 0,
1), D(0, 0, 0). Apply the scaling parameter 2 towards X axis, 3 towards
Y axis and 3 towards Z axis and obtain the new coordinates of the
object.
Solution-
Given-
• Old coordinates of the object = A (0, 3, 3), B(3, 3, 6), C(3, 0, 1),
D(0, 0, 0)
• Scaling factor along X axis = 2
• Scaling factor along Y axis = 3
• Scaling factor along Z axis = 3
For Coordinates A(0, 3, 3)
Let the new coordinates of A after scaling = (Xnew, Ynew, Znew).
Applying the scaling equations, we have-
Xnew = Xold x Sx = 0 x 2 = 0
Ynew = Yold x Sy = 3 x 3 = 9
Znew = Zold x Sz = 3 x 3 = 9
Thus, New coordinates of corner A after scaling = (0, 9, 9).
For Coordinates B(3, 3, 6)
Let the new coordinates of B after scaling = (Xnew, Ynew, Znew).
Applying the scaling equations, we have-
• Xnew = Xold x Sx = 3 x 2 = 6
• Ynew = Yold x Sy = 3 x 3 = 9
• Znew = Zold x Sz = 6 x 3 = 18
Thus, New coordinates of corner B after scaling = (6, 9, 18).
For Coordinates C(3, 0, 1)
Let the new coordinates of C after scaling = (Xnew, Ynew, Znew).
Applying the scaling equations, we have-
• Xnew = Xold x Sx = 3 x 2 = 6
• Ynew = Yold x Sy = 0 x 3 = 0
• Znew = Zold x Sz = 1 x 3 = 3
Thus, New coordinates of corner C after scaling = (6, 0, 3).
For Coordinates D(0, 0, 0)
Let the new coordinates of D after scaling = (Xnew, Ynew, Znew).
Applying the scaling equations, we have-
• Xnew = Xold x Sx = 0 x 2 = 0
• Ynew = Yold x Sy = 0 x 3 = 0
• Znew = Zold x Sz = 0 x 3 = 0
Thus, New coordinates of corner D after scaling = (0, 0, 0).