CST 304 COMPUTER GRAPHICS
AND
IMAGE PROCESSING
MODULE 2
AB CST 304 6/2/2022 1
SYLLABUS
Filled Area Primitives
Scan line polygon filling, Boundary filling and flood filling.
TRACE KTU
Two dimensional transformations-Translation, Rotation, Scaling,
Reflection and Shearing.
Composite transformations
Matrix representations and homogeneous coordinates.
Basic 3D transformations.
AB CST 304 6/2/2022 2
Polygon filling algorithm
Polygon
• A closed figure represented by a collection of more than 2 line segments
connected end to end.
• The line segments are known as “Edge” of the Polygon and make up the Polygon
boundary.
TRACE KTU
• Endpoints of the edges are known as “Vertex” of the Polygon.
22-09-2020 CS 401CG-Asha Baby 3
Types Of Polygon
• Simple Convex
• Simple Concave
• Non-simple : self-intersecting
TRACE KTU
22-09-2020 CS 401CG-Asha Baby 4
TRACE KTU
22-09-2020 CS 401CG-Asha Baby 5
TRACE KTU
22-09-2020 CS 401CG-Asha Baby 6
Polygon Filling
• Filling a Polygon is the process of coloring every pixel that comes inside the
Polygon region.
Techniques:
• Boundary Fill Method
TRACE KTU
• Flood Fill Method
• Scan – Line Fill Method
22-09-2020 CS 401CG-Asha Baby 7
Boundary Fill Method
• Boundary Fill Algorithm starts at a pixel inside the polygon to be filled and paints
the interior proceeding outwards towards the boundary.
• This algorithm works only if the color with which the region has to be filled and
the color of the boundary of the region are different.
TRACE KTU
• If the boundary is of one single color, this approach proceeds outwards pixel by
pixel until it hits the boundary of the region.
22-09-2020 CS 401CG-Asha Baby 8
Explanation
1. Draw a closed region using a boundary color.
2. Select an interior point (x,y). (any point that lies inside the
polygon)
3. Get the color of the pixel (x,y)
Color= getpixel(x,y)
TRACE KTU
If color not equal to boundary color and if that pixel is not already
colored
Then fill it with fill color.
AB CST 304 6/2/2022 9
• Boundary Fill Algorithm is recursive in nature. It takes an interior point(x, y), a
fill color, and a boundary color as the input.
• The algorithm starts by checking the color of (x, y).
• If it’s color is not equal to the fill color and the boundary color, then it is painted
with the fill color and the function is called for all the neighbours of (x, y).
TRACE KTU
• If a point is found to be of fill color or of boundary color, the function does not
call its neighbours and returns.
• This process continues until all points up to the boundary color for the region have
been tested.
22-09-2020 CS 401CG-Asha Baby 10
• The boundary fill algorithm can be implemented by 4-connected pixels or 8-
connected pixels.
• 4-connected pixels : After painting a pixel, the function is called for four
TRACE KTU
neighboring points.
• These are the pixel positions that are right, left, above and below the current pixel.
Areas filled by this method are called 4-connected.
22-09-2020 CS 401CG-Asha Baby 11
TRACE KTU
22-09-2020 CS 401CG-Asha Baby 12
4-Connected
void boundaryFill4(int x, int y, int fill_color,int boundary_color)
{ if(getpixel(x, y) != boundary_color && getpixel(x, y) != fill_color)
{ putpixel(x, y, fill_color);
TRACE KTU
boundaryFill4(x + 1, y, fill_color, boundary_color);
boundaryFill4(x, y + 1, fill_color, boundary_color);
boundaryFill4(x - 1, y, fill_color, boundary_color);
boundaryFill4(x, y - 1, fill_color, boundary_color);
}
}
22-09-2020 CS 401CG-Asha Baby 13
• 8-connected pixels : More complex figures are filled using this approach.
• The pixels to be tested are the 8 neighboring pixels, the pixel on the right, left,
above, below and the 4 diagonal pixels.
TRACE KTU
• Areas filled by this method are called 8-connected.
22-09-2020 CS 401CG-Asha Baby 14
void boundaryFill8(int x, int y, int fill_color,int boundary_color)
{ if(getpixel(x, y) != boundary_color && getpixel(x, y) != fill_color)
{ putpixel(x, y, fill_color); boundaryFill8(x + 1, y, fill_color,
boundary_color);
boundaryFill8(x, y + 1, fill_color, boundary_color);
boundaryFill8(x - 1, y, fill_color, boundary_color);
TRACE KTU
boundaryFill8(x, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y + 1, fill_color, boundary_color);
boundaryFill8(x + 1, y - 1, fill_color, boundary_color);
boundaryFill8(x + 1, y + 1, fill_color, boundary_color);
}
}
22-09-2020 CS 401CG-Asha Baby 15
Flood Fill Algorithm
➢ In this method, a point or seed which is inside region is selected. This
point is called a seed point.
➢ Then four connected approaches or eight connected approaches is used to
fill with specified color.
➢
TRACE KTU
Theflood fill algorithm has many characters similar to boundary fill.
But this method is more suitable for filling multiple colors boundary.
➢ When boundary is of many colors and interior is to be filled with one color
we use this algorithm.
67
• In fill algorithm, we start from a specified interior point (x, y)
and reassign all pixel values are currently set to a given interior
color with the desired color.
•
TRACE KTU
Using either a 4-connected or 8-connected approaches, we then
step through pixel
AB CST 304 6/2/2022 17
Explanation
Draw a closed region and fill the interior region with a color.
Select an interior point (x,y)
Get the color of interior pixel
TRACE KTU
Color = getpixel(x,y)
If color= old color
Setpixel(x,y)=new color
Continue until all pixels inside the region are replaced using new
color.
AB CST 304 6/2/2022 18
4-connected
Procedure floodfill (x, y,fill_ color, old_color: integer)
If (getpixel (x, y)=old_color)
{
setpixel (x, y, fill_color);
TRACE KTU
fill (x+1, y, fill_color, old_color);
fill (x-1, y, fill_color, old_color);
fill (x, y+1, fill_color, old_color);
fill (x, y-1, fill_color, old_color);
}
}
22-09-2020 CS 401CG-Asha Baby 19
8-connected
Procedure floodfill (x, y,fill_ color, old_color: integer) If (getpixel (x,
y)=old_color)
{
setpixel (x, y, fill_color);
fill (x+1, y, fill_color, old_color); fill (x-1, y, fill_color,
old_color);
TRACE KTU
fill (x, y+1, fill_color, old_color); fill (x, y-1, fill_color,
old_color); fill (x-1, y-1, fill_color, old_color); fill (x-1,
y+1, fill_color, old_color); fill (x+1, y-1, fill_color,
old_color); fill (x+1, y+1, fill_color, old_color).
}
}
22-09-2020 CS 401CG-Asha Baby 20
Disadvantage:
• Very slow algorithm
• May be fail for large polygons
• Initial pixel required more knowledge about surrounding pixels.
TRACE KTU
22-09-2020 CS 401CG-Asha Baby 21
Scan Line Polygon Fill Algorithm
Scan line algorithm is a process of filling regions of a polygon
that are geometrically defined by the coordinates of vertices of
this polygon graph.
TRACE KTU
This algorithm is specially used for the region filling just like the
boundary-fill and flood-fill algorithm.
The specialty of this algorithm is that it scans lines at a time
rather than scans a pixel.
This property makes it faster than others.
AB CST 304 6/2/2022 22
For a scan line polygon filling there are 3 steps to perform in the following order.
1. Find the intersections of the scan line with all edges of the polygon.
2. Sort the intersections by increasing x-coordinates ie, from left to right
TRACE KTU
3. Make pairs of the intersections and fill in color within all pixels inside the pair.
22-09-2020 CS 401CG-Asha Baby 23
Example
TRACE KTU
22-09-2020 CS 401CG-Asha Baby
24
The polygon edges are being intersected with the scanline by Scan
Line Algorithm. The polygon is filled with colours in between the
intersecting pairs. The practical working of the algorithm is shown
below:
Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 – From each edge of the polygon from Ymin to Ymax, all the
TRACE KTU
egdes are intersected by Scanline. Each of the points of intersection are
named as p0, p1, p2, p3.
Step 3 − Sort the intersection point in the increasing order of X
coordinate i.e. (p0, p1), (p1, p2), and (p2, p3).
Step 4 − Fill all those pair of coordinates that are inside polygons and
ignore the alternate pairs.
AB CST 304 6/2/2022 25
TRACE KTU
22-09-2020 CS 401CG-Asha Baby 26
• The slope of the polygon boundary line can be expressed in terms of the scan line
intersection coordinates
• m=(yk+1 - yk)/(xk+1 - xk )
• Since the change in y coordinates between the two scan lines is simply
yk+1 - yk = 1 TRACE KTU
The intersection value xk+1 , on the upper scan line can be determined from the x-
intersection value xk on the preceding scan line as,
xk+1 = xk + 1/m
each successive intercept can thus be calculated by adding the inverse of the slope
and rounding to the nearest integer.
22-09-2020 CS 401CG-Asha Baby 27
TRACE KTU
AB CST 304 6/2/2022 28
TRACE KTU
AB CST 304 6/2/2022 29
TRACE KTU
AB CST 304 6/2/2022 30
TRACE KTU
AB CST 304 6/2/2022 31
TRACE KTU
AB CST 304 6/2/2022 32
TRACE KTU
AB CST 304 6/2/2022 33
TRACE KTU
AB CST 304 6/2/2022 34
TRACE KTU
AB CST 304 6/2/2022 35
Problem
Explain scan line polygon filling algorithm. Determine the
content of the active edge table to fill the polygon with vertices
A( 2,4) B(4,6) C(4,1) for y= 1 to 6.
TRACE KTU
AB CST 304 6/2/2022 36
TRACE KTU
AB CST 304 6/2/2022 37
TRACE KTU
6/2/2022
AB CST 304 38
i First point Second point
1 (4,1) (4,1)
2 (3.3,2) (4,2)
3 (2.6,3) (4,3)
4 (2,4) (4,4)
5 (3,5) (4,5)
6 (4,6)
TRACE KTU
(4,6)
For each scan line from i= 1 to 6 fill color in between
each pair of intersections.
AB CST 304 6/2/2022 39
Inside Outside test
In Computer Graphics, Inside Outside is performed to test
whether a given point lies inside of a closed polygon or not.
Mainly, there are two methods to determine a point is
1.
TRACE KTU
interior/exterior to polygon:
Even-Odd / Odd-Even Rule or Odd Parity Rule
2. Winding Number Method
AB CST 304 6/2/2022 40
Even-Odd Rule / Odd Parity Rule
It is also known as crossing number and ray casting algorithm.
The algorithm follows a basic observation that if a ray coming
from infinity crosses through border of polygon, then it goes from
TRACE KTU
outside to inside and inside to outside alternately.
For every two crossings, point lies outside of polygon.
AB CST 304 6/2/2022 41
Algorithm:
Construct a line segment from point to be examined to point
outside of a polygon.
TRACE KTU
Count the number of intersections of line segment with polygon
boundaries.
If Odd number of intersection, then Point lies inside of Polygon.
Else, Point lies outside of polygon.
AB CST 304 6/2/2022 42
TRACE KTU
AB CST 304 6/2/2022 43
This test fails in case line segment intersects at vertex point. To
handle it, few modifications are made. Look at other end points of
two line segments of polygon.
If end points lie at same side of constructed line segment, then
even number of intersection is considered for that intersection
point.
TRACE KTU
If end points lie at opposite side of it, then odd number of
intersection is considered.
Time Complexity:
O(S) where S is the number of sides in the polygon
AB CST 304 6/2/2022 44
Winding Number / Non-Zero Algorithm
Alternative algorithm to perform test is Winding Number
algorithm.
TRACE KTU
A winding Number is calculated for given point with respect to
polygon.
If winding number is non-zero, then point lies inside the polygon.
Else, it lies outside of polygon.
AB CST 304 6/2/2022 45
Calculation of Winding Number
Conceptually, to check a point P, construct a line segment starting from
P to point on boundary.
TRACE KTU
Treat line segment to be elastic pinned at P. Stretch other end of elastic
around the polygon for one complete cycle.
Check how many times elastic has been wounded around point P.
If count is non-zero, then point lies inside of polygon. Else, outside of
polygon.
AB CST 304 6/2/2022 46
Another way to score up winding number is to assign a score for each
intersection with boundary of polygon and sum these numbers.
The score is given by considering direction of edge of polygon with
respect to line segment constructed.
Hence, directions are assigned to each edge of polygon in counter-
clock manner.
given. TRACE KTU
If side of edge starts from below of constructed line, then score -1 is
If edge starts from above of constructed line then score 1 is given.
Time Complexity:
O(S) where S is the number of sides in the polygon.
AB CST 304 6/2/2022 47
Example
TRACE KTU
AB CST 304 6/2/2022 48
Example
For a given figure,
1. For a top-most point, Winding number = (-1) + (1) + (-1) + (1) = 0
, lies outside.
TRACE KTU
2. For bottom-most point, Winding number = -1 , lies inside.
AB CST 304 6/2/2022 49
Two dimensional transformations
• The geometrical changes of an object from a current state to modified state.
• Changes in orientation, size and shape are accomplished with geometric
transformations that alter the coordinate descriptions of an object.
2 ways
TRACE KTU
Object Transformation
• Alter the coordinates descriptions an object
• Translation, rotation, scaling etc.
• Coordinate system unchanged
Coordinate transformation
• Produce a different coordinate system
6/2/2022 AB CST 304 50
The basic geometric transformations are,
• Translation
• Rotation
• Scaling
TRACE KTU
Other transformations
• Reflection
• Shear
6/2/2022 AB CST 304 51
TRACE KTU
6/2/2022 AB CST 304 52
• We translate a 2D point by adding translation distance tx and ty to the original
position (x,y) to move the point to a new position (x’,y’)
x’ = x+ tx
y’ = y+ ty
TRACE KTU
• Translation is a rigid body transformation that moves objects without deformation
, that is every point on the object is translated by the same amount.
6/2/2022 AB CST 304 53
TRACE KTU
6/2/2022 AB CST 304 54
TRACE KTU
6/2/2022 AB CST 304 55
Move an object with points (5,5) , (10,5) , (7.5,10) with a distance
(10,10)
P’ = P+T
P = [ (5,5) , (10,5) , (7.5,10)] , first draw the object before translation
T=(10,10)
TRACE KTU
So calculate P’ for all points
P’= [(15,15), (20,15), (17.5,20)]
Draw the translated object
6/2/2022 AB CST 304 56
TRACE KTU
6/2/2022 AB CST 304 57
TRACE KTU
6/2/2022 AB CST 304 58
TRACE KTU
6/2/2022 AB CST 304 59
• Clock wise (θ become negative)
• So R=cos(−𝛉) − sin(−𝛉)
sin(− 𝛉) cos(− 𝛉)
• cos(−𝛉) = cos 𝛉
• sin(−𝛉)= -sin(𝛉)
• P’= R.P
• =
cos(𝛉)
TRACE KTU
sin(𝛉) 𝑋
.
−sin( 𝛉) cos( 𝛉) 𝑌
• X’ = Xcos(𝛉) + 𝑌 sin(𝛉)
• Y’= -Xsin(𝛉) + 𝑌 cos(𝛉)
6/2/2022 AB CST 304 60
TRACE KTU
6/2/2022 AB CST 304 61
TRACE KTU
6/2/2022 AB CST 304 62
Rotation about a fixed point (xr , yr )
TRACE KTU
6/2/2022 AB CST 304 63
(x’- xr ) =cos(ø+ 𝛉).r
= rcos øcos 𝛉- rsinøsin 𝛉
= xcos 𝛉 -ysin 𝛉
= (x- xr)cos 𝛉 – (y- yr) sin 𝛉 where y = y- yr ; x=x- xr
(x’) = xr+(x- xr)cos 𝛉 – (y- yr) sin 𝛉
Find y’ ????? TRACE KTU
Rotations are rigid body transformations that move objects without
deformations.
6/2/2022 AB CST 304 64
6/2/2022 AB CST 304 65
6/2/2022 AB CST 304 66
6/2/2022 AB CST 304 67
Problems
• A Square object with the coordinate points P (1, 4), Q (4, 4), R (4, 1), T (1,1). Apply the
scaling factor 3 on the X-axis and 4 on the Y-axis. Find out the new coordinates of the
square?
• 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 for the given point (4,6) and
obtain the new coordinates of the object.
• A triangle ABC with coordinates A(0,0), B(6,5), C(6,0) is scaled with scaling factors
Sx=2 and Sy=3 about the vertex C(6,0). Find the transformed coordinate points. 4M
• Perform a 45 degree rotation of a triangle ABC having the vertices at A(0,0) B(10,10) and
C(50,20)
• i. About the origin
• ii. About an arbitrary point P(-10,-10) 6M
6/2/2022 AB CST 304 68
Scaling with respect to a fixed point (xf ,
yf )
• A polygon is then scaled relative to the fixed point by scaling the distance
from each vertex to the fixed point.
• For a vertex with coordinates (x,y) , the scaled coordinates (x’ , y’) are
calculated as
x’ = xf +(x- xf ).sx
y’ = yf +(y- yf ) .sy
• Rewrite these scaling transformations to separate multiplicative and additive
terms
x’ =xsx+ xf (1-sx )
y’ =ysy+ yf (1-sy )
• Where the additive terms xf (1-sx ) and yf (1-sy ) constants for all points in
the object.
6/2/2022 AB CST 304 69
• Perform the following transformations on a point (6, 4).
i) Translate by tx = −2 and ty = 4
ii) then, Scale by sx = 2 and sy = 1
iii) and Rotate by 90ο in clockwise direction. Determine
the final coordinates of the transformed point.
• Given a triangle A(20,10) B(80,20) C(50,70). Find the co-ordinates of vertices
after each of the following transformation.
Rotation of the triangle ABC about vertex A in clockwise direction for an angle
90 degree.
6/2/2022 AB CST 304 70
Matrix representations and homogenous coordinates
• Many graphics applications involve sequences of geometric transformations.
• An animation, for example, might require an object to be translated and rotated at each
increment of the motion.
• Here we reformulated the matrix representation of basic transformation . So that the
transformation sequences can be efficiently processed.
• Each of the basic transformations can be expressed in the general matrix form
P’=M1.P+ M2
• with coordinate positions P and P' represented as column vectors.
• Matrix M1 is a 2 by 2 array containing multiplicative factors, M2 and is a two-element
column matrix containing translational terms.
• For translation, M1 is the identity matrix.
• For rotation or scaling, M2 contains the translational terms associated with the pivot point
or scaling fixed point.
6/2/2022 AB CST 304 71
• To produce a sequence of transformations with these equations, such as scaling
followed by rotation then translation, we must calculate the transformed
coordinates one step at a time.
• First, coordinate positions are scaled, then these scaled coordinates are rotated, and
finally the rotated coordinates are translated.
• We can combine the multiplicative and translational terms for 2D geometric
transformations into a single matrix representation by expanding the 2 by 2 matrix
representations to 3 by 3 matrices.
• This allows us to express all transformation equations as matrix multiplications.
• we represent each Cartesian coordinate position (x,y) with the homogeneous
coordinate triple (xh , yh , h), where
x=xh/h
y=yh/h
6/2/2022 AB CST 304 72
• A general homogenous coordinate representation can also be written as (x.h , y.h,
h).
• For two-dimensional geometric transformations, we can choose the homogenous
parameter h to be any nonzero value.
• A convenient choice is simply to set h = 1.
• Each 2D position is then represented with homogeneous coordinates (x, y, 1).
6/2/2022 AB CST 304 73
6/2/2022 AB CST 304 74
6/2/2022 AB CST 304 75
6/2/2022 AB CST 304 76
Composite transformation
• we can set up a matrix for any sequence of transformations as a composite transformation
matrix by calculating the matrix product of the individual transformations.
• Forming products of transformation matrices is often referred to as a concatenation, or
composition, of matrices.
• For column matrix representation of coordinate positions, we form composite
transformations by multiplying matrices in order from right to left.
• That is, each successive transformation matrix premultiplies the product of the preceding
transformation matrices.
6/2/2022 AB CST 304 77
6/2/2022 AB CST 304 78
6/2/2022 AB CST 304 79
6/2/2022 AB CST 304 80
General pivot point rotation
6/2/2022 AB CST 304 81
6/2/2022 AB CST 304 82
6/2/2022 AB CST 304 83
General fixed point scaling
6/2/2022 AB CST 304 84
6/2/2022 AB CST 304 85
6/2/2022 AB CST 304 86
6/2/2022 AB CST 304 87
6/2/2022 AB CST 304 88
6/2/2022 AB CST 304 89
6/2/2022 AB CST 304 90
6/2/2022 AB CST 304 91
6/2/2022 AB CST 304 92
Different types
X- Shearing relative to the x axis
X- Shearing relative to the other reference line
Y- Shearing relative to y axis
Y- Shearing relative to the other reference line
XY shearing
AB CST 304 6/2/2022 93
X- Shearing relative to the x axis
X-Shear preserves the Y coordinate and changes are made to X coordinates.
Y- Shearing relative to y axis
Y-Shear preserves the X coordinate and changes are made to Y coordinates.
X shear
X-Y - Shearing
Here, both co – ordinates changes.
6/2/2022 AB CST 304 94
6/2/2022 AB CST 304 95
AB CST 304 6/2/2022 96
6/2/2022 AB CST 304 97
Sample problems
• Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the
reflection on the X axis and obtain the new coordinates of the object.
• Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the
reflection on the Y axis and obtain the new coordinates of the object.
• Given a triangle A(20,10) B(80,20) C(50,70). Find the co-ordinates of vertices
after each of the following transformation.
(a) Reflection about the line x=y.
(b) Rotation of the triangle ABC about vertex A in clockwise direction for an angle
90 degree.
6/2/2022 AB CST 304 98
• Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear
parameter 2 on X axis and 2 on Y axis and find out the new coordinates
of the object.
• Perform shearing for the given unit square A(0,0) B(1,0) C(1,1) D(0,1) relative to
the reference line Yref =- 2 and shx=1/2.
• Flip the given quadrilateral A(10,8) B(22,8) C(34,17) D(10,27) about the origin
and then zoom it to twice its size. Find the new position of the quadrilateral.
• Show that transformation matrix for a reflection about the line y=x is equivalent
to a reflection relative to the x axis followed by a counter clockwise rotation of
90 degree.
6/2/2022 AB CST 304 99
A triangle ABC with coordinates A(0,0), B(6,5), C(6,0) is scaled with
scaling factors Sx=2 and Sy=3 about the vertex C(6,0). Find the
transformed coordinate points.
Perform a 45 degree rotation of a triangle ABC having the vertices at
A(0,0) B(10,10) and C(50,20)
i. About the origin
ii. About an arbitrary point P(-10,-10)
Show that transformation matrix for a reflection about the line y=x is
equivalent to a reflection relative to the x axis followed by a counter
clockwise rotation of 90 degree.
6/2/2022 100
Perform the following transformations on a point (6, 4).
• Translate by tx = −2 and ty = 4
• then, Scale by sx = 2 and sy = 1
• and Rotate by 90 in clockwise direction. Determine the final
coordinates of the transformed point.
Prove that the multiplication of 2D transformation matrices for
two successive rotations is commutative.
AB CST 304 6/2/2022 101
Show that the composition of two successive rotations are
additive i.e. R(Ɵ1).
R(Ɵ2) = R(Ɵ1+ Ɵ2).
Consider a triangle at (2,2), (10,2), (2,10). Perform the following
2D transformations in succession and find the resultant vertices
(i) Scale with respect to (2,2) by scaling factors (2,2) respectively
along x and y directions.
(ii) Rotate by 90 counter clockwise direction.
AB CST 304 6/2/2022 102
Show that two successive reflections about either of the
coordinate axes is equivalent to a single rotation about the
coordinate origin.
Determine a sequence of basic transformations that are equivalent
to the x-direction shearing matrix.
Reflect a triangle ABC about the line 3x-4y+8=0. The position
vector of the coordinate ABC is given as A(4,1), B(5,2) and
C(4,3).
Describe the transformation which reflects a 2-D object about a
line L which has a y-intercept(0,b) and an angle of intersection
theta degree w.r.t. to the x-axis.
AB CST 304 6/2/2022 103
Basic 3D Transformations
• Methods for geometric transformations and object modelling in 3D are extended
from 2D methods by including the considerations for the z coordinates.
• 3D Transformations take place in a three dimensional plane. 3D
Transformations are important and a bit more complex than 2D Transformations.
• 3D translation
• 3D rotation
• 3D scaling
• 3D reflection
• 3D shearing
08-11-2020 CS401-CG Asha Baby VJEC 10
4
3D 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 (x’ y’ z’) after translation. Tx Ty Tz are translation
vectors in x, y, and z directions respectively.
08-11-2020 CS401-CG Asha Baby VJEC 10
5
x’=x+ Tx
y’=y+Ty
z’=z+ Tz
• In matrix form
• Translate the given point P(10,10,10) with a translation vector (10,20,5)
08-11-2020 CS401-CG Asha Baby VJEC 10
6
3D 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.
08-11-2020 CS401-CG Asha Baby VJEC 10
7
08-11-2020 CS401-CG Asha Baby VJEC 10
8
Z-axis rotation
08-11-2020 CS401-CG Asha Baby VJEC 10
9
X-axis rotation
08-11-2020 CS401-CG Asha Baby VJEC 11
0
Y-axis rotation
Rotate a point P(5,5,5) 90 degree about z-axis
08-11-2020 CS401-CG Asha Baby VJEC 11
1
Scaling
• Scaling is used to change the size of an object. The size can be increased or
decreased. The scaling three factors are required Sx Sy and Sz.
• Sx=Scaling factor in x- direction
Sy=Scaling factor in y-direction
Sz=Scaling factor in z-direction
• Scale the line AB with endpoint (10,20,10) and
(20,30,30) respectively with scaling factors (3,2,4)
08-11-2020 CS401-CG Asha Baby VJEC 11
2
Fixed point scaling
08-11-2020 CS401-CG Asha Baby VJEC 11
3
08-11-2020 CS401-CG Asha Baby VJEC 11
4
08-11-2020 CS401-CG Asha Baby VJEC 11
5
08-11-2020 CS401-CG Asha Baby VJEC 11
6
University questions..
What are the steps for general 3D rotation if the rotation axis is not
parallel to any one of the principal axis. The rotation axis is defined by
the points P1(x1,y1,z1) and P2(x2,y2,z2). Write down the composite
matrix representation.
Given a 3D triangle with points (0, 0, 0), (1, 1, 2) and (1, 1, 3). Apply
shear parameter 2 on X axis, 2 on Y axis and 3 on Z axis and find out
the new coordinates of the object.
Given a 3D triangle with coordinate points A(3, 4, 1), B(6, 4, 2), C(5,
6, and Apply the reflection on the XY plane and find out the new
coordinates of the object.
AB CST 304 6/2/2022 117
Given a 3D triangle with coordinate points A(3, 4, 1), B(6, 4, 2),
C(5, 6, 3). Apply the reflection on the XZ plane and find out the
new coordinates of the object.
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.
Given a homogeneous point (1, 2, 3). Apply rotation 90 degree
towards X, Y and Z axis and find out the new coordinate points.
AB CST 304 6/2/2022 118
Given a 3D object with coordinate points A(0, 3, 1), B(3, 3, 2),
C(3, 0, 0), D(0, 0, 0). Apply the translation with the distance 1
towards X axis, 1 towards Y axis and 2 towards Z axis and obtain
the new coordinates of the object.
What are the steps for general 3D rotation if the rotation axis is
not parallel to any one of the principal axis. The rotation axis is
defined by the points P1(x1,y1,z1) and P2(x2,y2,z2). Write down
the composite matrix representation.
Describe the steps involved in scaling a 3D object with respect to
a fixed point (xf, yf, zf). Derive the composite transformation
matrix.
AB CST 304 6/2/2022 119
A rectangular parallelepiped is unit distance on Z-axis, 2 units on
X-axis and 3 units on Y-axis. Determine the new coordinates of
the parallelepiped when it is rotated counter clockwise about X-
axis by an angle of 45 and Magnify the triangle ABC with A(0,
0), B(1, 1) and C(5, 2) to twice its size while keeping C(5, 2)
fixed.
Write the 3D translation matrix for moving an object by -2 units, -
4 units and -6 units respectively in x, y and z directions.
AB CST 304 6/2/2022 120