Study session 2 CSC 433
Study session 2 CSC 433
Introduction
In this study session, you will learn about line and circle algorithm such as Digital Differential
Analyzer (DDA) algorithm, the Bresenham algorithm, mid-point algorithm
In a line generation algorithm, a line connects two points. It is a basic element in graphics. To draw
a line, you need two points between which you can draw a line. In the following three algorithms,
we refer the one point of line as X0, Y0 and the second point of line as X1, Y1.
In a circle generating algorithm, drawing a circle on the screen is a little complex than drawing a
line. There are two popular algorithms for generating a circle: Bresenham’s Algorithm and
Midpoint Circle Algorithm. These algorithms are based on the idea of determining the subsequent
points required to draw the circle.
Page 1 of 16
CSC 433: Computer Graphic and Visualization
dx = X1 - X0
dy = Y1 -
Y0
Step 3: Based on the calculated difference in step-2, you need to identify the number of steps to put
pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.
Steps = absolute(dx);
else
Steps = absolute(dy);
Page 2 of 16
CSC 433: Computer Graphic and Visualization
Y increment = dy / (float)
steps;
Step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and complete
the drawing of the line
x = x + Xincrement;
y = y +
Yincrement;
putpixel(x,y);
Page 3 of 16
CSC 433: Computer Graphic and Visualization
For example, as shown in the following illustration, from position (2, 3) you need to choose
between (3, 3) and (3, 4). You would like the point that is closer to the original line.
At sample position xk+1, the vertical separations from the mathematical line are labelled as d upper
and d lower.
Page 4 of 16
CSC 433: Computer Graphic and Visualization
Now you need to decide whether to put the next point at E or N. This can be chosen by identifying
the intersection point Q closest to the point N or E. If the intersection point Q is closest to the point
N then N is considered as the next point; otherwise E.
To determine that, first calculate the mid-point M(x+1, y + ½). If the intersection point Q of the line
with the vertical line connecting E and N is below M then take E as the next point; otherwise take N
as the next point.
F(x,y) = mx + b – y
Page 5 of 16
CSC 433: Computer Graphic and Visualization
Page 6 of 16
CSC 433: Computer Graphic and Visualization
Page 7 of 16
CSC 433: Computer Graphic and Visualization
Algorithm
Step 1: Get the coordinates of the center of the circle and radius, and store them in x, y, and R
respectively. Set P=0 and Q=R.
Step 2: Set decision parameter D = 3 – 2R. Step 3: Repeat through step-8 while X < Y. Step 4: Call
Draw Circle (X, Y, P, Q).
Page 8 of 16
CSC 433: Computer Graphic and Visualization
Page 9 of 16
CSC 433: Computer Graphic and Visualization
di+1 = di +
2xi+1 + 2yi+1 + 1
di+1 = di + 2yi+1 + 1
Page 10 of 16
CSC 433: Computer Graphic and Visualization
Step 5: Move each calculate pixel position (X, Y) onto the circular path centered on
X = X + XC,
Y = Y + YC
Page 11 of 16
CSC 433: Computer Graphic and Visualization
1. There are two popular algorithms for generating a circle: Bresenham’s Algorithm and
Midpoint Circle Algorithm.
2. The full meaning of DDA algorithm is Digital Differential Analyzer
3. The Bresenham algorithm is another incremental scan conversion algorithm.
4. The big advantage of Bresenham algorithm is that, it uses only integer calculations 5.
Page 12 of 16
CSC 433: Computer Graphic and Visualization
Pilot Answer
Glossary of Terms
Page 13 of 16
CSC 433: Computer Graphic and Visualization
Page 14 of 16
CSC 433: Computer Graphic and Visualization
SAQ2.1
The major advantage of Bresenham algorithm is that, it uses only integer calculations
SAQ 2.2
Page 15 of 16
CSC 433: Computer Graphic and Visualization
REFERENCE
1. John F, Hughes, Andries Van Dam, Morgan McGuire(2013). Computer Graphics
principles
and practices. Mexico city: Printed in United State
2. www.tutorialpoint.com
Page 16 of 16