Module – 1(Basics of Computer graphics and
Algorithms)
• Basics of Computer Graphics and its applications.
Video Display devices- Refresh Cathode Ray Tubes,
Random Scan Displays and systems, Raster scan
displays and systems.
• Line drawing algorithms- DDA, Bresenham’s algorithm.
Circle drawing algorithms- Midpoint Circle generation
algorithm, Bresenham’s algorithm.
• 1. Beam Penetration Method :
Beam Penetration Method is quite similar to the normal CRT and it uses only one electron
gun. In this, different colors of multi-layered are coated on inner surface of screen,
normally the two layers of phosphorus i.e., red and green are coated. It is a method used
for displaying color pictures that has been used with random scan monitors.
• 2. Shadow Mask Method :
Shadow Mask Method is the method which is used in raster scan system which includes
color TVs. In this the pixel is made up of three -colors. So due to three colors it uses three
electron guns one for producing each color. The colors are red, green and blue. In this the
important consideration for a color monitor is the setting of electron guns and the
phosphor dots forming a pixel.
Line drawing algorithms
• The Line drawing algorithm is a graphical algorithm which is used to
represent the line segment on discrete graphical media, i.e., printer and
pixel-based media.
• A line contains two points. The point is an important element of a line
Equation of the straight line
We can define a straight line with the help of the following equation.
y= mx + a
• Where,
DDA (Digital Differential Analyzer)
• Simplest line drawing algorithm.
• Digital Differential Analyzer algorithm is also known as an incremental
method of scan conversion. Previous step results are used in the next
step.
• Digital Differential Analyzer algorithm is used to perform rasterization
on polygons, lines, and triangles etc
Algorithm of Digital Differential Analyzer (DDA) Line Drawing
Step 1: Start.
Step 2: We consider Starting point as (x1, y1), and ending point (x2, y2).
Step 3: Now, we have to calculate Δx and Δy.
Δx = x2-x1
Δy = y2-y1
m = Δy/Δx
Step 4: Now, we calculate three cases.
If m < 1
Then x change in Unit Interval
y moves with deviation
(xk+1, yk+1) = (xk+1, yk+m)
If m > 1
Then x moves with deviation
y change in Unit Interval
(xk+1, yk+1) = (xk+1/m, yk+1)
If m = 1
Then x moves in Unit Interval
y moves in Unit Interval
(xk+1, yk+1) = (xk+1, yk+1)
Step 5: We will repeat step 4 until we find the ending point of the line.
Step 6: Stop.
Problems
• There is a system with resolution 640 X 480. Calculate the size of
the frame buffer to store 12 bits per pixel?
Solution
Resolution = 640 X 480
Number of bits/pixel = N = 12
Required Frame Buffer Memory = N X Resolution
= 12 X 640 X 480
Memory in bytes = (12 x 640 X 480) / 8
= 460800 Bytes
Memory in KB = 460800/1024
= 450 KB
There is a system with resolution 1280 X 1024. Find out the size of frame buffer in
bytes and kilobytes, if 9 bits per pixel are stored. Also find out how many colors can
be displayed?
Solution
Resolution = 1280 X 1024
Number of bits/pixel = N = 9
Required Frame Buffer Memory = N X Resolution
= 9 X 1280 X 1024
Memory in bytes = (9 X 1280 X 1024) / 8
= 1474560 Bytes
Memory in KB = 1474560/1024 = 1440 KB
• If there are n bits per pixel then we can have a total of 2n colors.
Here we have 9 bits per pixel, so,
Total number of colors = 2n = 29= 512 colors
There are two raster systems with resolutions of 1280×1024, and 2560×2048.
a) Tell the size of the frame buffer (in bytes) for each of these systems to store 12
bits/pixel? b) How much storage is required for each system if we store 24 bits per
pixel?
1280 x 1024 x 12 bits / 8 = 1920KB
2560 x 2048 x 12 bits / 8 = 7680KB
Consider two raster systems with the resolutions of 640 x 480 and 1280 x 1024.
a) How many pixels could be accessed per second in each of these systems by a
display controller that refreshes the screen at a rate of 60 frames per second?
Solution
Since 60 frames are refreshed per second and each frame consists of 640 x 480 pixels,
the access rate of such a system is (640 x 480) * 60 = 1.8432 x 107 pixels/second.
Likewise, for the 1280 x 1024 system, the access rate is (1280 x 1024) * 60 = 7.86432 x 107 pixels/second.
Line equation
The slope-intercept form of a line is written as
• To illustrate Bresenham’s approach, we first consider the scan conversion
process for lines with positive slope less than 1
• Pixel positions along a line path are the determined by sampling at unit x
intervals.
• Starting from the left end point( x0,y0) of a given line, we step to each
successive column(x position) and plot the pixel whose scan line y value is
closest to the line path
Calculate the points between the starting coordinates (9, 18) and
ending coordinates (14, 22).
Calculate ΔX and ΔY from the given input.
ΔX = Xn – X0 = 14 – 9 = 5
ΔY =Yn – Y0 = 22 – 18 = 4
Calculate the decision parameter.
Pk= 2ΔY – ΔX = 2 x 4 – 5 = 3
So, decision parameter Pk = 3
As Pk >= 0, so case-02 is satisfied.
Thus,
k+1 k
• P = P + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
• Xk+1 = Xk + 1 = 9 + 1 = 10
• Yk+1 = Yk + 1 = 18 + 1 = 19
Similarly, Step-03 is executed until the end point is reached or number of iterations
equals to 5 times.
(Number of iterations = ΔX =5 times)
x y p
9 18 3
10 19 1
11 20 -1
12 20 7
13 21 5
14 22 3
Calculate the points between the starting coordinates (20, 10) and ending coordinates (30, 18).
dx=10 dy=8 2dy=16
Pk=2dy-dx= 16-10=6
2dy-2dx= 16-20 = -4
x y p
20 10 6
21 11 2
22 12 -2
23 12 14
24 13 10
25 14 6
26 15 2
27 16 -2
28 16 14
29 17 10
30 18 6
Píoblem-
02:
Given the centre point coordinates (4, 4) and radius as 10, generate all
the points to form a circle.
Given-
Centre Coordinates of Circle (X0, Y0) = (4, 4)
Radius of Circle = 10
The following table shows the generation of points
for Quadrant-1-
Xplot = Xc + X0 = 4 + X0
Yplot = Yc + Y0 = 4 + Y0
Bresenham’s Circle Drawing Algorithm
Bresenham’s algorithm is also used for circle drawing.
It is known as Bresenhams’s circle drawing algorithm.
Let us assume we have a point p (x, y) on the boundary of the circle and with r radius
satisfying the equation fc (x, y) = 0
We assume,
The distance between point P3 and circle boundary = d1
The distance between point P2 and circle boundary = d2
Now, if we select point P3 then circle equation will be-
d1 = (xk +1)2 + (yk)2 – r2 {Value is +ve, because the point is
outside the circle}
if we select point P2 then circle equation will be-
d2 = (xk +1)2 + (yk –1)2 – r2 {Value is -ve, because the point is
inside the circle}
Now, we will calculate the decision parameter
(dk) = d1 + d2
dk =(xk +1)2 + (yk)2 – r2 + (xk +1)2 + (yk –1)2 – r2
= 2(xk +1)2 + (yk)2+ (yk -1)2 – 2r2 ……… (1)
If
dk < 0
then
Point P3 is closer to circle boundary, and the final coordinates are-
(xk +1, yk) = (xk +1, yk)
If
dk >= 0
then
Point P2 is closer to circle boundary, and the final coordinates are-
(xk +1, yk) = (xk +1, yk -1)
Now, we will find the next decision parameter (dk+1)
(dk+1) = 2(xk+1 +1)2 + (yk+1)2+ (yk+1 -1)2 – 2r2 …………… (2)
Now, we find the difference between decision parameter equation (2) – equation
(1)
(dk+1) – (dk) = 2(xk+1+1)2 + (yk+1)2+ (yk+1 –1)2 – 2r2 – 2(xk +1)2 + (yk)2+ (yk– 1)2 –
2r2
(dk+1) = dk + 4xk + 2(yk+1
2– yk
2) –2 (yk+1 – yk) + 6
Algorithm of Bresenham’s Circle Drawing
Step 1: Start.
Step 2: First, we allot the starting coordinates (x1, y1) as follows-
x1 = 0
y1 =r
Step 3: Now, we calculate the initial decision parameter d0 –
d0 = 3 – 2 x r
Step 4: Assume,the initial coordinates are (xk, yk)
The next coordinates will be (xk+1, yk+1)
Now, we will find the next point of the first octant according to the value of the decision parameter
(dk).
Step 5: Now, we follow two cases-
Case 1: If
dk < 0
then
xk+1 =xk + 1
yk+1 =yk
dk+1 = dk + 4xk+1 + 6
Case 2: If
dk >= 0
then
xk+1 =xk + 1
yk+1 =yk –1
dk+1 = dk + 4(xk+1 – yk+1)+ 10
Step 6: If the center coordinates (x1, y1) is not at the origin (0, 0), then we will draw the points as follow-
X coordinate = xc + x1
y coordinate = yc + y1 {xc andyc representsthe current value of x and y coordinate}
Step 7: We repeat step 5 and 6 until we get x>=y.
Step 8: Stop.
Example
The radius of a circle is 8, and center point coordinates are (0, 0). Apply
bresenham’s circle drawing algorithm to plot all points of the circle.
Solution:
Step 1: The given stating points of the circle (x1, y1) = (0, 0)
Radius of the circle (r) = 8
Step 2: Now, we will assign the starting point (x1, y1) as follows-
x1 = 0
y1 = r (radius) = 8
Step 3: Now, we will calculate the initial decision parameter (d0)
d0 = 3 – 2 x r
d0 = 3 – 2 x 8
d0 = -13
Step 4: The value of initial parameter d0 < 0. So, case 1 is satisfied.
Thus,
xk+1 =xk + 1 = 0 + 1 = 1
yk+1 =yk = 8
dk+1 = dk + 4xk+1 + 6 = –13 + (4 x 1) + 6 = –3
Step 5: The center coordinates are already (0, 0) so we will move to next step.
Step 6: Follow step 4 until we get x >= y.