1
UNIT 4
Geometry and Line Generation
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.
DDAAlgorithm
Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm which is
explained step by step here.
Step 1: Get the input of two end points (X0, Y0) and (X1, Y1).
Step 2: Calculate ΔX, ΔY and M from the given input.
These parameters are calculated as-
• ΔX = Xn – X0
• ΔY =Yn – Y0
• M = ΔY / ΔX
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).
Find the next point by following the below three cases-
2
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)
Step-01: Calculate ΔX, ΔY and M from the given input.
• ΔX = Xn – X0 = 8 – 5 = 3
• ΔY =Yn – Y0 = 12 – 6 = 6
• M = ΔY / ΔX = 6 / 3 = 2
Step-02: Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6
3
Step-03: As M > 1, so case-03 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.
Xp Yp
Xp+
1
Yp+
1
Round off (Xp+1,
Yp+1)
5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
7.5 11 (8, 11)
8 12 (8, 12)
Example 2: Calculate the points between the starting point (1, 7) and ending point (11, 17).
Given-
• Starting coordinates = (X0, Y0) = (1, 7)
• Ending coordinates = (Xn, Yn) = (11, 17)
Step-01: Calculate ΔX, ΔY and M from the given input.
• ΔX = Xn – X0 = 11 – 1 = 10
4
• Δ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.
Xp Yp
Xp+
1
Yp+
1
Round off (Xp+1,
Yp+1)
1 7 2 8 (2, 8)
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)
5
Advantages of DDAAlgorithm-
• 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 DDAAlgorithm-
• 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.
Bresenham’s Line Generation Algorithm
The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this
algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each
step choose between two different y coordinates.
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 dupper and dlower.
convert the output primitives into frame buffer
6
Step-01: Calculate ΔX and ΔY from the given input.
These parameters are calculated as-
• ΔX = Xn – X0
• ΔY =Yn – Y0
Step-02: Calculate the decision parameter Pk.
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.
Follow the below two cases-
7
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-
• Starting coordinates = (X0, Y0) = (9, 18)
• Ending coordinates = (Xn, Yn) = (14, 22)
Step-01: Calculate ΔX and ΔY from the given input.
• ΔX = Xn – X0 = 14 – 9 = 5
• ΔY =Yn – Y0 = 22 – 18 = 4
Step-02: Calculate the decision parameter.
Pk= 2ΔY – ΔX
= 2 x 4 – 5 = 3
8
So, decision parameter Pk = 3
Step-03: As Pk >= 0, so case-02 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
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
Pk+
1
Xk+
1
Yk+1
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
9
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 DDAAlgorithm.
• The points generated by this algorithm are more accurate than DDAAlgorithm.
• It uses fixed points only.
Disadvantages of Bresenham Line Drawing Algorithm-
The disadvantages of Bresenham Line Drawing Algorithm are-
• Though it improves the accuracy of generated points but still the resulted line is not smooth.
• This algorithm is for the basic line drawing.
• It can not handle diminishing jaggies.
Mid-Point line drawing Algorithm
Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van Aken. Assume that
you have already put the point P at (x, y) coordinate and the slope of the line is 0 ≤ k ≤ 1 as shown in
the following illustration.
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.
10
The points generation using Mid Point Line Drawing Algorithm involves the following steps-
Step-01: Calculate ΔX and ΔY from the given input.
These parameters are calculated as-
• ΔX = Xn – X0
• ΔY =Yn – Y0
Step-02: Calculate the value of initial decision parameter and ΔD.
These parameters are calculated as-
Dinitial = 2ΔY – ΔX
• ΔD = 2(ΔY – ΔX)
Step-03: The decision whether to increment X or Y coordinate depends upon the flowing values of
Dinitial.
Follow the below two cases-
11
Step-04: Keep repeating Step-03 until the end point is reached.
For each Dnew value, follow the above cases to find the next coordinates.
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)
Step-01: Calculate ΔX and ΔY from the given input.
• ΔX = Xn – X0 = 30 – 20 = 10
• ΔY =Yn – Y0 = 18 – 10 = 8
Step-02: Calculate Dinitial and ΔD as-
• Dinitial = 2ΔY – ΔX = 2 x 8 – 10 = 6
• ΔD = 2(ΔY – ΔX) = 2 x (8 – 10) = -4
Step-03: As Dinitial >= 0, so case-02 is satisfied.,
• Xk+1 = Xk + 1 = 20 + 1 = 21
• Yk+1 = Yk + 1 = 10 + 1 = 11
• Dnew = Dinitial + ΔD = 6 + (-4) = 2
Similarly, Step-03 is executed until the end point is reached.
Dinitia
l
Dne
w
Xk+
1
Yk+1
20 10
6 2 21 11
2 -2 22 12
-2 14 23 12
14 10 24 13
10 6 25 14
6 2 26 15
2 -2 27 16
-2 14 28 16
14 10 29 17
12
10 30 18
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.
Circle Generation 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. Let us discuss the
algorithms in detail:
The equation of circle is X2 + Y2 = r2, where r is radius.
Bresenham’s Circle Drawing Algorithm
Given-
13
• Centre point of Circle = (X0, Y0)
• Radius of Circle = R
The points generation using Bresenham Circle Drawing Algorithm involves the following steps-
Step-01: Assign the starting point coordinates (X0, Y0) as-
• X0 = 0
• Y0 = R
Step-02: Calculate the value of initial decision parameter P0 as-
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.
Follow the below two cases-
14
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
Here, (Xc, Yc) denotes the current value of X and Y coordinates.
Step-05: Keep repeating Step-03 and Step-04 until Xplot => Yplot.
Step-06: Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry property of circle.
This is depicted by the following figure-
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
Step-01: Assign the starting point coordinates (X0, Y0) as-
• X0 = 0
15
• Y0 = R = 8
Step-02: Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R
P0 = 3 – 2 x 8
P0 = -13
Step-03: As Pinitial < 0, so case-01 is satisfied.
Thus,
• Xk+1 = Xk + 1 = 0 + 1 = 1
• Yk+1 = Yk = 8
• Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3
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)
-13 -3 (1, 8)
-3 11 (2, 8)
11 5 (3, 7)
5 7 (4, 6)
7 (5, 5)
Algorithm Terminates
These are all points for Octant-1.
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y coordinates.
Octant-1 Points Octant-2 Points
(0, 8) (5, 5)
(1, 8) (6, 4)
(2, 8) (7, 3)
16
(3, 7) (8, 2)
(4, 6) (8, 1)
(5, 5) (8, 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-
Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-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)
(8, 0) (-8, 0) (-8, 0) (8, 0)
These are all points of the Circle.
Advantages of Bresenham Circle Drawing Algorithm-
The advantages of Bresenham Circle Drawing Algorithm are-
• The entire algorithm is based on the simple equation of circle X2 + Y2 = R2.
• It is easy to implement.
Disadvantages of Bresenham Circle Drawing Algorithm
• Like Mid Point Algorithm, accuracy of the generating points is an issue in this algorithm.
• This algorithm suffers when used to generate complex and high graphical images.
• There is no significant enhancement with respect to performance.
Mid Point Algorithm
17
The points generation using Mid Point Circle Drawing Algorithm involves the following steps-
Step-01: Assign the starting point coordinates (X0, Y0) as-
• X0 = 0
• Y0 = R
Step-02: Calculate the value of initial decision parameter P0 as-
P0 = 1 – 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.
Follow the below two cases-
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
Here, (Xc, Yc) denotes the current value of X and Y coordinates.
18
Step-05: Keep repeating Step-03 and Step-04 until Xplot >= Yplot.
Step-06: Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry property of circle.
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
• Y0 = R = 10
Step-02: Calculate the value of initial decision parameter P0 as-
P0 = 1 – R
P0 = 1 – 10
P0 = -9
Step-03: As Pinitial < 0, so case-01 is satisfied.
Thus,
• Xk+1 = Xk + 1 = 0 + 1 = 1
• Yk+1 = Yk = 10
• Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6
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)
19
6 -3 (4, 9)
-3 8 (5, 9)
8 5 (6, 8)
Algorithm Terminates
These are all points for Octant-1.
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y coordinates.
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-
Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-Y)
(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)
20
(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)
(10, 0) (-10, 0) (-10, 0) (10, 0)
These are all points of the Circle.
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.

More Related Content

PPTX
Algorithm.pptx
PPTX
Chapter 3 - Part 1 [Autosaved].pptx
PDF
Chapter 2 Computer graphics by Kushal Bhattarai
PPTX
dddddddddddddddddddddddddddddddddddddddddddddddddddddAlgorithm.pptx
PPT
1 linedrawing
PPT
Graphics6 bresenham circlesandpolygons
PPT
Graphics6 bresenham circlesandpolygons
PPTX
Output primitives in Computer Graphics
Algorithm.pptx
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 2 Computer graphics by Kushal Bhattarai
dddddddddddddddddddddddddddddddddddddddddddddddddddddAlgorithm.pptx
1 linedrawing
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
Output primitives in Computer Graphics

Similar to UNIT 4-geometry of which and line drawing.pdf (20)

PPT
2.Line,circle drawing.ppt line circlw drawing algorith
PDF
Line drawing Algorithm DDA in computer Graphics.pdf
PPT
Bresenham circles and polygons derication
PPT
Bresenham circlesandpolygons
PDF
module 1.pdf
PDF
cgrchapter2version-1-200729063505 (1).pdf
PDF
Computer graphics 2
PPTX
Line Drawing Algorithms - Computer Graphics - Notes
PPTX
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
PDF
Unit 2
PPTX
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
DOCX
Dda algo notes
PPT
computer_graphics_line_algorithm in Computer Graphics
PPTX
Study on Fundamentals of Raster Scan Graphics
PDF
Computer Graphics Unit 2
PPTX
Computer Graphics
PDF
Computer graphics notes watermark
PPT
Lines and curves algorithms
PDF
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
PDF
2.2. interactive computer graphics
2.Line,circle drawing.ppt line circlw drawing algorith
Line drawing Algorithm DDA in computer Graphics.pdf
Bresenham circles and polygons derication
Bresenham circlesandpolygons
module 1.pdf
cgrchapter2version-1-200729063505 (1).pdf
Computer graphics 2
Line Drawing Algorithms - Computer Graphics - Notes
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
Unit 2
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Dda algo notes
computer_graphics_line_algorithm in Computer Graphics
Study on Fundamentals of Raster Scan Graphics
Computer Graphics Unit 2
Computer Graphics
Computer graphics notes watermark
Lines and curves algorithms
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
2.2. interactive computer graphics
Ad

More from naolseyum9 (8)

PDF
Chapter 5- 3D transformations of graphics.pdf
PDF
Chapter 3 - Searching and prPlanning.pdf
PDF
Intro to AI of [chapter 6-7- 8 ] (1).pdf
PDF
Chapter 5 - Machine which of Learning.pdf
PDF
artificial intelligence Chapter 6 - NLP.pdf
PDF
Chapter 5 - Machine of it Learning (1).pdf
PDF
Chapter 4 - Knowledge Representation and Reasoning (1).pdf
PDF
Chapter word of it Intelligent Agents.pdf
Chapter 5- 3D transformations of graphics.pdf
Chapter 3 - Searching and prPlanning.pdf
Intro to AI of [chapter 6-7- 8 ] (1).pdf
Chapter 5 - Machine which of Learning.pdf
artificial intelligence Chapter 6 - NLP.pdf
Chapter 5 - Machine of it Learning (1).pdf
Chapter 4 - Knowledge Representation and Reasoning (1).pdf
Chapter word of it Intelligent Agents.pdf
Ad

Recently uploaded (20)

PDF
ARCHITECTURE LIENSURE EXAMINATION FLASHCARDS REVIEW
PPTX
class12chemicalkinetics-240104162115-fe1ed3c1.pptx
PPTX
ChatGPT_Webinar_Slides.vgggggggggggggggpptx
PDF
Pfthuujhgdddtyygghjjiuyggghuiiiijggbbhhh
PDF
The Value of Professional Graphic Design
PPT
2 Development_Processes_and Organizations.ppt
PDF
commercial kitchen design for owners of restaurants and hospitality
PPTX
interesting case discu.pptxkkkkkkkkkkkkk
PPTX
CVS MODULE 2.pptxjjjjjjjjjjjjkkkkjjiiiiii
PPT
GIT Bleeding presentation for undergrads
PPTX
Anjali synopsis seminar (15) (1) (1).pptx
PDF
This presentation is made for a design foundation class at Avantika Universit...
PDF
Design and Work Portfolio by Karishma Goradia
PPT
Diabetes_vogt for undergraduate students
PDF
Control and coordination isdorjdmdndjke
PPTX
UNITy8 human computer interac5ion-1.pptx
PDF
Capture One Pro 16.6.5.17 for MacOS Crack Free Download New Version 2025
PPTX
Chapter-3-educ-8 Program outcomes & SLOs
PPTX
Applied Anthropology Report.pptx paulapuhin
PPTX
Textile fibers are classified based on their origin, composition, and structu...
ARCHITECTURE LIENSURE EXAMINATION FLASHCARDS REVIEW
class12chemicalkinetics-240104162115-fe1ed3c1.pptx
ChatGPT_Webinar_Slides.vgggggggggggggggpptx
Pfthuujhgdddtyygghjjiuyggghuiiiijggbbhhh
The Value of Professional Graphic Design
2 Development_Processes_and Organizations.ppt
commercial kitchen design for owners of restaurants and hospitality
interesting case discu.pptxkkkkkkkkkkkkk
CVS MODULE 2.pptxjjjjjjjjjjjjkkkkjjiiiiii
GIT Bleeding presentation for undergrads
Anjali synopsis seminar (15) (1) (1).pptx
This presentation is made for a design foundation class at Avantika Universit...
Design and Work Portfolio by Karishma Goradia
Diabetes_vogt for undergraduate students
Control and coordination isdorjdmdndjke
UNITy8 human computer interac5ion-1.pptx
Capture One Pro 16.6.5.17 for MacOS Crack Free Download New Version 2025
Chapter-3-educ-8 Program outcomes & SLOs
Applied Anthropology Report.pptx paulapuhin
Textile fibers are classified based on their origin, composition, and structu...

UNIT 4-geometry of which and line drawing.pdf

  • 1. 1 UNIT 4 Geometry and Line Generation 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. DDAAlgorithm Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm which is explained step by step here. Step 1: Get the input of two end points (X0, Y0) and (X1, Y1). Step 2: Calculate ΔX, ΔY and M from the given input. These parameters are calculated as- • ΔX = Xn – X0 • ΔY =Yn – Y0 • M = ΔY / ΔX 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). Find the next point by following the below three cases-
  • 2. 2 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) Step-01: Calculate ΔX, ΔY and M from the given input. • ΔX = Xn – X0 = 8 – 5 = 3 • ΔY =Yn – Y0 = 12 – 6 = 6 • M = ΔY / ΔX = 6 / 3 = 2 Step-02: Calculate the number of steps. As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6
  • 3. 3 Step-03: As M > 1, so case-03 is satisfied. Now, Step-03 is executed until Step-04 is satisfied. Xp Yp Xp+ 1 Yp+ 1 Round off (Xp+1, Yp+1) 5 6 5.5 7 (6, 7) 6 8 (6, 8) 6.5 9 (7, 9) 7 10 (7, 10) 7.5 11 (8, 11) 8 12 (8, 12) Example 2: Calculate the points between the starting point (1, 7) and ending point (11, 17). Given- • Starting coordinates = (X0, Y0) = (1, 7) • Ending coordinates = (Xn, Yn) = (11, 17) Step-01: Calculate ΔX, ΔY and M from the given input. • ΔX = Xn – X0 = 11 – 1 = 10
  • 4. 4 • Δ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. Xp Yp Xp+ 1 Yp+ 1 Round off (Xp+1, Yp+1) 1 7 2 8 (2, 8) 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)
  • 5. 5 Advantages of DDAAlgorithm- • 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 DDAAlgorithm- • 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. Bresenham’s Line Generation Algorithm The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each step choose between two different y coordinates. 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 dupper and dlower. convert the output primitives into frame buffer
  • 6. 6 Step-01: Calculate ΔX and ΔY from the given input. These parameters are calculated as- • ΔX = Xn – X0 • ΔY =Yn – Y0 Step-02: Calculate the decision parameter Pk. 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. Follow the below two cases-
  • 7. 7 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- • Starting coordinates = (X0, Y0) = (9, 18) • Ending coordinates = (Xn, Yn) = (14, 22) Step-01: Calculate ΔX and ΔY from the given input. • ΔX = Xn – X0 = 14 – 9 = 5 • ΔY =Yn – Y0 = 22 – 18 = 4 Step-02: Calculate the decision parameter. Pk= 2ΔY – ΔX = 2 x 4 – 5 = 3
  • 8. 8 So, decision parameter Pk = 3 Step-03: As Pk >= 0, so case-02 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 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 Pk+ 1 Xk+ 1 Yk+1 9 18 3 1 10 19 1 -1 11 20 -1 7 12 20 7 5 13 21 5 3 14 22
  • 9. 9 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 DDAAlgorithm. • The points generated by this algorithm are more accurate than DDAAlgorithm. • It uses fixed points only. Disadvantages of Bresenham Line Drawing Algorithm- The disadvantages of Bresenham Line Drawing Algorithm are- • Though it improves the accuracy of generated points but still the resulted line is not smooth. • This algorithm is for the basic line drawing. • It can not handle diminishing jaggies. Mid-Point line drawing Algorithm Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van Aken. Assume that you have already put the point P at (x, y) coordinate and the slope of the line is 0 ≤ k ≤ 1 as shown in the following illustration. 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.
  • 10. 10 The points generation using Mid Point Line Drawing Algorithm involves the following steps- Step-01: Calculate ΔX and ΔY from the given input. These parameters are calculated as- • ΔX = Xn – X0 • ΔY =Yn – Y0 Step-02: Calculate the value of initial decision parameter and ΔD. These parameters are calculated as- Dinitial = 2ΔY – ΔX • ΔD = 2(ΔY – ΔX) Step-03: The decision whether to increment X or Y coordinate depends upon the flowing values of Dinitial. Follow the below two cases-
  • 11. 11 Step-04: Keep repeating Step-03 until the end point is reached. For each Dnew value, follow the above cases to find the next coordinates. 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) Step-01: Calculate ΔX and ΔY from the given input. • ΔX = Xn – X0 = 30 – 20 = 10 • ΔY =Yn – Y0 = 18 – 10 = 8 Step-02: Calculate Dinitial and ΔD as- • Dinitial = 2ΔY – ΔX = 2 x 8 – 10 = 6 • ΔD = 2(ΔY – ΔX) = 2 x (8 – 10) = -4 Step-03: As Dinitial >= 0, so case-02 is satisfied., • Xk+1 = Xk + 1 = 20 + 1 = 21 • Yk+1 = Yk + 1 = 10 + 1 = 11 • Dnew = Dinitial + ΔD = 6 + (-4) = 2 Similarly, Step-03 is executed until the end point is reached. Dinitia l Dne w Xk+ 1 Yk+1 20 10 6 2 21 11 2 -2 22 12 -2 14 23 12 14 10 24 13 10 6 25 14 6 2 26 15 2 -2 27 16 -2 14 28 16 14 10 29 17
  • 12. 12 10 30 18 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. Circle Generation 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. Let us discuss the algorithms in detail: The equation of circle is X2 + Y2 = r2, where r is radius. Bresenham’s Circle Drawing Algorithm Given-
  • 13. 13 • Centre point of Circle = (X0, Y0) • Radius of Circle = R The points generation using Bresenham Circle Drawing Algorithm involves the following steps- Step-01: Assign the starting point coordinates (X0, Y0) as- • X0 = 0 • Y0 = R Step-02: Calculate the value of initial decision parameter P0 as- 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. Follow the below two cases-
  • 14. 14 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 Here, (Xc, Yc) denotes the current value of X and Y coordinates. Step-05: Keep repeating Step-03 and Step-04 until Xplot => Yplot. Step-06: Step-05 generates all the points for one octant. To find the points for other seven octants, follow the eight symmetry property of circle. This is depicted by the following figure- 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 Step-01: Assign the starting point coordinates (X0, Y0) as- • X0 = 0
  • 15. 15 • Y0 = R = 8 Step-02: Calculate the value of initial decision parameter P0 as- P0 = 3 – 2 x R P0 = 3 – 2 x 8 P0 = -13 Step-03: As Pinitial < 0, so case-01 is satisfied. Thus, • Xk+1 = Xk + 1 = 0 + 1 = 1 • Yk+1 = Yk = 8 • Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3 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) -13 -3 (1, 8) -3 11 (2, 8) 11 5 (3, 7) 5 7 (4, 6) 7 (5, 5) Algorithm Terminates These are all points for Octant-1. Algorithm calculates all the points of octant-1 and terminates. Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y coordinates. Octant-1 Points Octant-2 Points (0, 8) (5, 5) (1, 8) (6, 4) (2, 8) (7, 3)
  • 16. 16 (3, 7) (8, 2) (4, 6) (8, 1) (5, 5) (8, 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- Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-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) (8, 0) (-8, 0) (-8, 0) (8, 0) These are all points of the Circle. Advantages of Bresenham Circle Drawing Algorithm- The advantages of Bresenham Circle Drawing Algorithm are- • The entire algorithm is based on the simple equation of circle X2 + Y2 = R2. • It is easy to implement. Disadvantages of Bresenham Circle Drawing Algorithm • Like Mid Point Algorithm, accuracy of the generating points is an issue in this algorithm. • This algorithm suffers when used to generate complex and high graphical images. • There is no significant enhancement with respect to performance. Mid Point Algorithm
  • 17. 17 The points generation using Mid Point Circle Drawing Algorithm involves the following steps- Step-01: Assign the starting point coordinates (X0, Y0) as- • X0 = 0 • Y0 = R Step-02: Calculate the value of initial decision parameter P0 as- P0 = 1 – 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. Follow the below two cases- 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 Here, (Xc, Yc) denotes the current value of X and Y coordinates.
  • 18. 18 Step-05: Keep repeating Step-03 and Step-04 until Xplot >= Yplot. Step-06: Step-05 generates all the points for one octant. To find the points for other seven octants, follow the eight symmetry property of circle. 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 • Y0 = R = 10 Step-02: Calculate the value of initial decision parameter P0 as- P0 = 1 – R P0 = 1 – 10 P0 = -9 Step-03: As Pinitial < 0, so case-01 is satisfied. Thus, • Xk+1 = Xk + 1 = 0 + 1 = 1 • Yk+1 = Yk = 10 • Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6 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)
  • 19. 19 6 -3 (4, 9) -3 8 (5, 9) 8 5 (6, 8) Algorithm Terminates These are all points for Octant-1. Algorithm calculates all the points of octant-1 and terminates. Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y coordinates. 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- Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-Y) (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)
  • 20. 20 (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) (10, 0) (-10, 0) (-10, 0) (10, 0) These are all points of the Circle. 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.