UNIT 4-Geometry and Line Drawing
UNIT 4-Geometry and Line Drawing
Step 3: Find the number of steps or points in between the starting and ending coordinates.
if (absolute (ΔX) > absolute (ΔY))
Steps = absolute (ΔX);
else
Steps = absolute (ΔY);
Step 4: Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).
1
Step 5: Keep repeating Step-04 until the end point is reached or the number of generated new points
(including the starting and ending points) equals to the steps count.
Example 1 : Calculate the points between the starting point (5, 6) and ending point (8, 12).
Solution-
Given-
• Starting coordinates = (X0, Y0) = (5, 6)
• Ending coordinates = (Xn, Yn) = (8, 12)
Example 2: Calculate the points between the starting point (1, 7) and ending point (11, 17).
Given-
• ΔX = Xn – X0 = 11 – 1 = 10
3
• ΔY =Yn – Y0 = 17 – 7 = 10
• M = ΔY / ΔX = 10 / 10 = 1
Step-02: Calculate the number of steps.
As |ΔX| = |ΔY| = 10 = 10, so number of steps = ΔX = ΔY = 10
Step-03: As M = 1, so case-02 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.
4
Advantages of DDA Algorithm-
• It is a simple algorithm.
• It is easy to implement.
• It avoids using the multiplication operation which is costly in terms of time complexity.
Disadvantages of DDA Algorithm-
• There is an extra overhead of using round off( ) function.
• Using round off( ) function increases time complexity of the algorithm.
• Resulted lines are not smooth because of round off( ) function.
• The points generated by this algorithm are not accurate.
5
Step-01: Calculate ΔX and ΔY from the given input.
It is calculated as-
Pk = 2ΔY – ΔX
Step-03: Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point depending on the value of decision parameter Pk.
6
Step-04: Keep repeating Step-03 until the end point is reached or number of iterations
equals to (ΔX-1) times.
Example : Calculate the points between the starting coordinates (9, 18) and ending coordinates (14, 22).
Given-
=2x4–5=3
7
So, decision parameter Pk = 3
Similarly, Step-03 is executed until the end point is reached or number of iterations equals to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
Pk+ Xk+
Pk Yk+1
1 1
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
8
Advantages of Bresenham Line Drawing Algorithm-
The advantages of Bresenham Line Drawing Algorithm are-
• It is easy to implement.
• It is fast and incremental.
• It executes fast but less faster than DDA Algorithm.
• The points generated by this algorithm are more accurate than DDA Algorithm.
• It uses fixed points only.
9
The points generation using Mid Point Line Drawing Algorithm involves the following steps-
For each Dnew value, follow the above cases to find the next coordinates.
10
Example: Calculate the points between the starting coordinates (20, 10) and ending coordinates (30,
18).
Given-
• Starting coordinates = (X0, Y0) = (20, 10)
• Ending coordinates = (Xn, Yn) = (30, 18)
• Dinitial = 2ΔY – ΔX = 2 x 8 – 10 = 6
• ΔD = 2(ΔY – ΔX) = 2 x (8 – 10) = -4
11
Advantages of Mid Point Line Drawing Algorithm-
The advantages of Mid Point Line Drawing Algorithm are-
• Accuracy of finding points is a key feature of this algorithm.
• It is simple to implement.
• It uses basic arithmetic operations.
• It takes less time for computation.
• The resulted line is smooth as compared to other line drawing algorithms.
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. Let us discuss the
algorithms in detail:
The equation of circle is X2 + Y2 = r2, where r is radius.
P0 = 3 – 2 x R
Step-03: Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter Pk.
12
Step-04: If the given centre point (X0, Y0) is not (0, 0), then do the following and plot
the point-
• Xplot = Xc + X0
• Yplot = Yc + Y0
Step-05: Keep repeating Step-03 and Step-04 until Xplot => Yplot.
13
Example: Given the center point coordinates (0, 0) and radius as 8, generate all the points to form a
circle.
Given-
• Centre Coordinates of Circle (X0, Y0) = (0, 0)
• Radius of Circle = 8
• X0 = 0
• Y0 = R = 8
P0 = 3 – 2 x 8
P0 = -13
Step-04: This step is not applicable here as the given centre point coordinates is (0,
0).
Step-05: Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-
Pk Pk+1 (Xk+1, Yk+1)
(0, 8)
14
-13 -3 (1, 8)
-3 11 (2, 8)
11 5 (3, 7)
5 7 (4, 6)
7 (5, 5)
Algorithm Terminates
Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y coordinates.
Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant-1-
• X0 = 0
• Y0 = R
Step-03: Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter Pk.
16
Step-04: If the given centre point (X0, Y0) is not (0, 0), then do the following and
plot the point-
• Xplot = Xc + X0
• Yplot = Yc + Y0
Step-05: Keep repeating Step-03 and Step-04 until Xplot >= Yplot.
Example: Given the center point coordinates (0, 0) and radius as 10, generate all the points to form a
circle.
Given-
• Centre Coordinates of Circle (X0, Y0) = (0, 0)
• Radius of Circle = 10
Step-01: Assign the starting point coordinates (X0, Y0) as-
• X0 = 0
17
• Y0 = R = 10
P0 = 1 – 10
P0 = -9
Step-04: This step is not applicable here as the given centre point coordinates is (0,
0).
Step-05: Step-03 is executed similarly until Xk+1 >= Yk+1 as follows-
Pk Pk+1 (Xk+1, Yk+1)
(0, 10)
-9 -6 (1, 10)
-6 -1 (2, 10)
-1 6 (3, 10)
6 -3 (4, 9)
-3 8 (5, 9)
8 5 (6, 8)
Algorithm Terminates
18
Octant-1 Points Octant-2 Points
(0, 10) (8, 6)
(1, 10) (9, 5)
(2, 10) (9, 4)
(3, 10) (10, 3)
(4, 9) (10, 2)
(5, 9) (10, 1)
(6, 8) (10, 0)
These are all points for Quadrant-1.
Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant-1-
19
Advantages of Mid Point Circle Drawing Algorithm-
The advantages of Mid Point Circle Drawing Algorithm are-
• It is a powerful and efficient algorithm.
• The entire algorithm is based on the simple equation of circle X2 + Y2 = R2.
• It is easy to implement from the programmer’s perspective.
• This algorithm is used to generate curves on raster displays.
20