Professional Documents
Culture Documents
Example: A line has a starting point (1,7) and ending point (11,17). Apply the Digital Differential
Analyzer algorithm to plot a line.
Δx = Δy = 10
3 9 (3, 9)
4 10 (4, 10)
5 11 (5, 11)
6 12 (6, 12)
7 13 (7, 13)
8 14 (8, 14)
9 15 (9, 15)
10 16 (10, 16)
11 17 (11, 17)
Step 4: We will repeat step 3 until we get the endpoints of the line.
Step 5: Stop.
This algorithm was introduced by “Jack Elton Bresenham” in 1962. This algorithm helps us to perform
scan conversion of a line. It is a powerful, useful, and accurate method. We use incremental integer
calculations to draw a line. The integer calculations include addition, subtraction, and multiplication.
In Bresenham’s Line Drawing algorithm, we have to calculate the slope (m) between the starting point
and the ending point.
As shown in the above figure let, we have initial coordinates of a line = (xk, yk) The next coordinates of a
line = (xk+1, yk+1)
The intersection point between yk and yk+1 = y Let we assume that the distance between y and yk = d1
The distance between y and yk+1 = d2 ,Now, we have to decide which point is nearest to the intersection
point.
Case 1: If
pk < 0
Then
pk+1 =pk +2Δy
xk+1 = xk +1
yk+1 = yk
Case 2: If
pk >= 0
Then
pk+1 =pk +2Δy-2Δx
xk+1 =xk +1
yk+1 =yk +1
Step 6: We will repeat step 5 until we found the ending point of the line and the total
number of iterations =Δx-1.
Step 7: Stop.
Example: A line has a starting point (9,18) and ending point (14,22). Apply the
Bresenham’s Line Drawing algorithm to plot a line.
Solution: We have two coordinates,
Starting Point = (x1, y1) = (9,18)
Ending Point = (x2, y2) = (14,22)
Step 1: First, we calculate Δx, Δy.
Δx = x2 – x1 = 14-9 = 5
Δy = y2 – y1 = 22-18 = 4
Step 2: Now, we are going to calculate the decision parameter (pk)
pk = 2Δy-Δx
= 2 x 4 – 5 = 3
The value of pk = 3
Step 3: Now, we will check both the cases.
If
pk >= 0
Then
Case 2 is satisfied. Thus
pk+1 = pk +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
Step 4: Now move to next step. We will calculate the coordinates until we reach the end
point of the line.
Δx -1 = 5 – 1 = 4
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
Step 5: Stop.
It is fast to apply but not faster than the Digital Differential Analyzer (DDA) algorithm.
The pointing accuracy is higher than the DDA algorithm.
Disadvantages of Bresenham’s Line Drawing Algorithm
The Bresenham’s Line drawing algorithm only helps to draw the basic line.
The Mid-point Subdivision algorithm helps to compute or calculate the visible areas of lines that
appear in the window. This line plotting algorithm follows the bisection method to divide the line
into equal partitions.
Step 1: Start.
Step 2: Consider the starting point as (x1, y1) and ending point as (x2, y2).
Step 4: Now, we will calculate the decision parameter di with the following formula.
di = 2Δy - Δx
Step 6: We will repeat step 5 until we found the ending point of the line.
Step 7: Stop.
Example: A line has a starting point (6,10) and ending point (13,17). Apply the Mid-point
Line Drawing algorithm to draw a line. (Exercise). The final answers, Coordinates of drawn
lines are- P1 = (6, 10), P2 = (7, 11), P3 = (8, 12), P4 = (9, 13), P5 = (10, 14), P6 = (11, 15), P7 =
(12, 16), P8 = (13, 17).
A circle is an eight-way symmetric shape. All quadrants of a circle are the same. There are two octants in
each quadrant of a circle. If we know the value of any point, then we can easily calculate the values of the
remaining seven points by using the eight-way symmetry method. A circle is a shape consist of a line
called the circumference. All the straight lines drawn from a particular point within the circle to the
circumference are always equal. A circle is a round shape that has no corner or sides.
If we want to draw a circle, then we will consider it by its origin point. Let us assume a point
P1(R, S) then we can represent the other seven points as follows-P2(R, -S), P3(-R, -S), P4(-R, S),
P5(S, R), P6(S, -R), P7(-S, -R), P8(-S, R).
Example: Let, we have taken a point (4, 6) of a circle. We will calculate the remaining seven
points by using of reflection method as follows- The seven points are – (4, -6), (-4, -6), (-4, 6),
(4, 6), (4, -6), (-4, -6), (-4, 6)
drawing a line. In this algorithm, we will select the closest pixel position to complete the arc. We
cannot represent the continuous arc in the raster display system. The different part of this
algorithm is that we only use arithmetic integer. We can perform the calculation faster than other
algorithms.
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
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 and yc represents the 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)
d =3–2xr
0
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.
Table for all points of octant 1:
(0, 8)
Now, we will calculate the coordinates of the octant 2 by swapping the x and y coordinates.
Thus, we will calculate all points of the circle with respect to octant 1.
Quadrant 1 (x,
Quadrant 2 (-x, y) Quadrant 3 (-x, -y) Quadrant 4 (x, -y)
y)
(0, 8) (0, 8) (0, -8) (0, -8)
(1, 8) (-1, 8) (-1, -8) (1, -8)
(2, 8) (-2, 8) (-2, -8) (2, -8)
(3, 7) (-3, 7) (-3, -7) (3, -7)
(4, 6) (-4, 6) (-4, -6) (4, -6)
(5, 5) (-5, 5) (-5, -5) (5, -5)
(6, 4) (-6, 4) (-6, -4) (6, -4)
(7, 3) (-7, 3) (-7, -3) (7, -3)
(8, 2) (-8, 2) (-8, -2) (8, -2)
(8, 1) (-8, 1) (-8, -1) (8, -1)
d =1–r
0
Example: The center coordinates are (0, 0), and the radius of the circle is 10. Find all
points of the circle by using the midpoint circle drawing algorithm?
Solution:
Step 1: The given center coordinates of the circle (p0, q0) = (0, 0)
Radius of the circle (r) = 10
Step 2: Now, we will determine the starting coordinates (p0, q0) as follows-
P0 = 0
q0 = r (radius) = 10
Step 3: Now, we will determine the initial decision parameter (d0)
d = 1 –r
0
(0, 10) (0, 10) (0, -10) (0, -10)
(1, 10) (-1, 10) (-1, -10) (1, -10)
(2, 10) (-2, 10) (-2, -10) (2, -10)
(3, 10) (-3, 10) (-3, -10) (3, -10)
(4, 9) (-4, 9) (-4, -9) (4, -9)
(5, 9) (-5, 9) (-5, -9) (5, -9)
(6, 8) (-6, 8) (-6, -8) (6, -8)
(8, 6) (-8, 6) (-8, -6) (8, -6)
(9, 5) (-9, 5) (-9, -5) (9, -5)
(9, 4) (-9, 4) (-9, -4) (9, -4)
(10, 3) (-10, 3) (-10, -3) (10, -3)
(10, 2) (-10, 2) (-10, -2) (10, -2)
(10, 1) (-10, 1) (-10, -1) (10, -1)
It is a time-consuming algorithm.
Sometimes the points of the circle are not accurate.
We can understand ellipse as an elongated circle. In the midpoint ellipse drawing algorithm, we
will determine the plotting point (p, q). Let us suppose that the center point of the ellipse is (0,
0).
Step 3: Wecalculate the initial value and decision parameter for region 1 as follow-
dp = 2r2qp
Do
{plot (p, q)
If (dk1 < 0)
(p= p+1 and q = q)
dk1 = dk1 – dp + r2q
}
Else
dq = dq - 2r2p
dk1 = dk1 + dp - dp + r2q
} while (dp < dq)
Step 6: Now ,we calculate the initial value and decision parameter for region 2 as follow-
Do
{plot (p, q)
If (dk2 < 0)
(p= p and q = q - 1)
dk2 = dk2 – dq + r2p
}
Else
dp = dp + 2r2q
dk2 = dk2 + dp – dq + r2p
} while (q < 0)
Step 9: Stop.
Review exercise
1. Given the centre point coordinates (4, -4) and radius as 10, generate all the
points to form a circle. Using mid-point circle drawing algorithm.
2. Plot the ellipse centered at (0, 0) with radius rx = 8 and ry = 6, using mid-
point ellipse drawing algorithm.
3. Implement the DDA algorithm to draw a line from (0,0) to (6,6). M = (6-0)/
(6-0) =6/6 =1 XK+1=Xk+1 YK+1=Yk+m = Yk+1 Xk=0 Yk=0