SlideShare a Scribd company logo
Computer Graphics
CS-443
Lecture 8
“Bresenham’s Line Algorithm”
By:
Faiz.Ur.Rehman
Lecturer in Computer Science
faiz.rehmanpk@yahoo.com
Index
o The Bresenham algorithm
o Review
o The Big Idea
o Deriving The Bresenham Line Algorithm
o The Bresenham Line Algorithm
o Examples
o Tasks
o Summary
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
2
Objective of the today’s topic
• To Understand the basic concept of line drawing
algorithm.
• To Study that how line is draw on raster display.
• To understand a mathematical background of
Bresenham’s line algorithm.
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
3
The Bresenham Line Algorithm
• The Bresenham algorithm is
another incremental scan
conversion algorithm
• The big advantage of this algorithm
is that it uses only integer
calculations
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
4
Jack Bresenham worked for 27
years at IBM before entering
academia. Bresenham developed
his famous algorithms at IBM in
t h e e a r l y 1 9 6 0 s
Review
• Point Slope Line Equation:
• y = m.x + b
• Slope:
• m = y2 − y1 / x2 − x1 = Δy / Δx
• y-intercept
• b = y1 − m.x1
• x-interval
• Δx = Δy / m
• y-interval
• Δy = m Δx
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
5
The Big Idea
• Move across the x axis in unit intervals and at each step
choose between two different y coordinates
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
6
2 3 4 5
2
4
3
5
(xk, yk)
(xk+1, yk)
(xk+1, yk+1)
(Previous)
NE (next)
E (next)
• For example, from
position (2, 3) we have to
choose between (3, 3)
and (3, 4)
• We would like the pixel
that is closer to the
original line
Deriving the Bresenham line algorithm
• At sample position xk+1 the vertical separations from
the mathematical line are labelled dupper and dlower
• The y coordinate on the mathematical line at xk+1 is:
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
7
b
x
m
y k +
+
= )
1
(
y
yk
yk+1
xk+1
dlower
dupper
Deriving the Bresenham line algorithm (cont…)
• So, dupper and dlower are given as follows:
• and:
• We can use these equations to make a simple decision
about which pixel is closer to the mathematical line.
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
8
k
lower y
y
d −
=
k
k
Lower y
b
x
m
d −
+
+
= )
1
(
y
y
d k
upper −
+
= )
1
(
b
x
m
y k
k −
+
−
+
= )
1
(
1
Deriving the Bresenham line algorithm (cont…)
• This simple decision is based on the difference between
the two pixel positions:
• Let’s substitute m with ∆y/∆x where ∆x and ∆y are the
differences between the end-points:
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
9
1
2
2
)
1
(
2 −
+
−
+
=
− b
y
x
m
d
d k
k
upper
lower
)
)
1
(
1
(
)
)
1
(
( b
x
m
y
y
b
x
m
d
d k
k
k
k
Uper
Lower −
+
−
+
−
−
+
+
=
−
)
1
2
2
)
1
(
2
(
)
( −
+
−
+



=
−
 b
y
x
x
y
x
d
d
x k
k
upper
lower
)
1
2
(
2
2
2 −

+

+


−


= b
x
y
y
x
x
y k
k
c
y
x
x
y k
k +


−


= 2
2
The Bresenham line algorithm
• BRESENHAM’S LINE DRAWING ALGORITHM
(for |m| < 1.0)
1. Input the two line end-points, storing the left end-
point in (x0, y0)
2. Plot the point (x0, y0)
3. Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx)
and get the first value for the decision parameter as:
4. At each xk along the line, starting at k = 0, perform the
following test. If pk < 0, the next point to plot is
(xk+1, yk) and:
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
10
x
y
p 
−

= 2
0
y
p
p k
k 
+
=
+ 2
1
The Bresenham line algorithm
Otherwise, the next point to plot is (xk+1, yk+1) and:
5. Repeat step 4 (Δx – 1) times
• The algorithm and derivation above assumes slopes are
less than 1. for other slopes we need to adjust the
algorithm slightly.
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
11
x
y
p
p k
k 
−

+
=
+ 2
2
1
Example 1
• Let the given end points for the line be (30,20) and (40, 28)
• M = dy = y2 – y1 = 28 – 20 = 8
• dx x2 – x1 40 – 30 = 10
• m = 0.8
• dy = 8 and dx = 10
• The initial decision parameter P0 is
• P0 = 2dy – dx = 2(8) – 10 = 16 – 10 = 6
• P0 = 6>0, there x and y will be increase with interval one.
• The constants 2dy and 2dy-2dx are
• 2dy = 2(8) = 16 2dy-2dx = 2(8)- 2(10) =16 – 20
• 2dy = 16 2dy – 2dx = - 4
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
12
Example 1 (cont…)
• End points (30,20) (40,28)
• dx=x2-x1=40-30=10 dy= y2-y1=28-20=8
• P0=2dy-dx=2X8-10 = 6 >0 pt(31,21)
• Pk+1= pk+2dy-2dx= 6+16-20 =2 >0 (32,22)
• Pk+1=2+16-20 =-2 <0 (33,22)
• Pk+1= pk+2dy =-2+16 = 14 >0 (34,23)
• Pk+1= pk+2dy-2dx=14+16-20=10>0 (35,24)
• Pk+1=10+16-20=6 >0 (36,25)
• Pk+1= 6+16-20=2>0 (37,26)
• Pk+1=2+16-20=-2 <0 (38,26)
• Pk+1= pk+2dy=-2+16=14>0 (39,27)
• Pk+1=pk+2dy-2dx= 14+16-20=10>0 (40,28)
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
13
Example 1 (cont…)
• The starting point (x0, y0)=(30,20) and the successive
pixel positions are given in the following table
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
14
K Pk (Xk+1, Yk+1)
0 6 (31,21)
1 2 32,22
2 -2 33,22
3 14 34,23
4 10 35,24
5 6 36,25
6 2 37,26
7 -2 38,26
8 14 39,27
9 10 40,28
Example 2
• We plot the initial point (x0 , y0)=(20,10) and (x1 , y1)=
(30,18)
• determine successive pixel positions along the line path
from the decision parameter as.
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
15
K pk (xk +1, yk +1) K pk (xk +1, yk +1)
0 6 (21,11) 5 6 (26,15)
1 2 (22,12) 6 2 (27,16)
2 -2 (23,12) 7 -2 (28,16)
3 14 (24,13) 8 14 (29,17)
4 10 (25,14) 9 10 (30,18)
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
16
Example 2
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
17
Task 1
• Consider the line from (5, 8) to (9,11),use general
Bresenham’s line algorithm to rasterize this line.
Evaluate and tabulate all the steps involved.
18
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
Task 2
• Consider the line from (0, 0) to (-8,-4), use general
Bresenham’s line algorithm to rasterize this line.
Evaluate and tabulate all the steps involved.
19
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
Bresenham Line Algorithm Summary
• The Bresenham line algorithm has the following
advantages:
• A fast incremental algorithm
• Uses only integer calculations
• Comparing this to the DDA algorithm, DDA has the
following problems:
• Accumulation of round-off errors can make the pixelated line
drift away from what was intended
• The rounding operations and floating-point arithmetic
involved are time consuming
20
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
Assignment No.1
• Explore the Bresenham’s line algorithm procedure
(for |m| >1.0)
Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
21
CG08 - Bresenham’s Line Algorithm Data structure.pdf

More Related Content

Similar to CG08 - Bresenham’s Line Algorithm Data structure.pdf (20)

Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
R S Anu Prabha
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
Kumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
Muhammad Fiaz
 
Bresenhems line Genration derivation for Mtech
Bresenhems line Genration derivation for MtechBresenhems line Genration derivation for Mtech
Bresenhems line Genration derivation for Mtech
rahulkatre9
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
Sneha Chopra
 
Chapter 2 Computer graphics by Kushal Bhattarai
Chapter 2 Computer graphics by Kushal BhattaraiChapter 2 Computer graphics by Kushal Bhattarai
Chapter 2 Computer graphics by Kushal Bhattarai
idontwannatellmyname
 
dokumen.tips_scan-conversion-568812b73d987.ppt
dokumen.tips_scan-conversion-568812b73d987.pptdokumen.tips_scan-conversion-568812b73d987.ppt
dokumen.tips_scan-conversion-568812b73d987.ppt
RishuV1
 
BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
St Mary's College,Thrissur,Kerala
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
Kumar
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
aa11bb11
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
IndhuMcamphil
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
Alamelu
 
1 linedrawing
1 linedrawing1 linedrawing
1 linedrawing
SakshiNailwal
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
RobinAhmedSaikat
 
Computer Graphics_Module 2_Output Primitives.pdf
Computer Graphics_Module 2_Output Primitives.pdfComputer Graphics_Module 2_Output Primitives.pdf
Computer Graphics_Module 2_Output Primitives.pdf
tabbu23
 
Bresenham line-drawing-algorithm By S L Sonawane.pdf
Bresenham line-drawing-algorithm By S L Sonawane.pdfBresenham line-drawing-algorithm By S L Sonawane.pdf
Bresenham line-drawing-algorithm By S L Sonawane.pdf
SujataSonawane11
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
SanthiNivas
 
Computer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmComputer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithm
Ruchi Maurya
 
Graphics 2 Output Primitives Slide.pdf
Graphics 2 Output Primitives   Slide.pdfGraphics 2 Output Primitives   Slide.pdf
Graphics 2 Output Primitives Slide.pdf
IsabelleAlemu
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
Thirunavukarasu Mani
 
Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
R S Anu Prabha
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
Kumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
Muhammad Fiaz
 
Bresenhems line Genration derivation for Mtech
Bresenhems line Genration derivation for MtechBresenhems line Genration derivation for Mtech
Bresenhems line Genration derivation for Mtech
rahulkatre9
 
Chapter 2 Computer graphics by Kushal Bhattarai
Chapter 2 Computer graphics by Kushal BhattaraiChapter 2 Computer graphics by Kushal Bhattarai
Chapter 2 Computer graphics by Kushal Bhattarai
idontwannatellmyname
 
dokumen.tips_scan-conversion-568812b73d987.ppt
dokumen.tips_scan-conversion-568812b73d987.pptdokumen.tips_scan-conversion-568812b73d987.ppt
dokumen.tips_scan-conversion-568812b73d987.ppt
RishuV1
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
Kumar
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
aa11bb11
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
IndhuMcamphil
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
Alamelu
 
Computer Graphics_Module 2_Output Primitives.pdf
Computer Graphics_Module 2_Output Primitives.pdfComputer Graphics_Module 2_Output Primitives.pdf
Computer Graphics_Module 2_Output Primitives.pdf
tabbu23
 
Bresenham line-drawing-algorithm By S L Sonawane.pdf
Bresenham line-drawing-algorithm By S L Sonawane.pdfBresenham line-drawing-algorithm By S L Sonawane.pdf
Bresenham line-drawing-algorithm By S L Sonawane.pdf
SujataSonawane11
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
SanthiNivas
 
Computer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmComputer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithm
Ruchi Maurya
 
Graphics 2 Output Primitives Slide.pdf
Graphics 2 Output Primitives   Slide.pdfGraphics 2 Output Primitives   Slide.pdf
Graphics 2 Output Primitives Slide.pdf
IsabelleAlemu
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
Thirunavukarasu Mani
 

Recently uploaded (20)

Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdfDr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivashankar
 
22PCOAM16 Machine Learning Unit V Full notes & QB
22PCOAM16 Machine Learning Unit V Full notes & QB22PCOAM16 Machine Learning Unit V Full notes & QB
22PCOAM16 Machine Learning Unit V Full notes & QB
Guru Nanak Technical Institutions
 
Java Programming Language: until 2025 and beyond
Java Programming Language: until 2025 and beyondJava Programming Language: until 2025 and beyond
Java Programming Language: until 2025 and beyond
arzu TR
 
BEC602- Module 3-2-Notes.pdf.Vlsi design and testing notes
BEC602- Module 3-2-Notes.pdf.Vlsi design and testing notesBEC602- Module 3-2-Notes.pdf.Vlsi design and testing notes
BEC602- Module 3-2-Notes.pdf.Vlsi design and testing notes
VarshithaP6
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine
 
Advanced Concrete Technology- Properties of Concrete
Advanced Concrete Technology- Properties of ConcreteAdvanced Concrete Technology- Properties of Concrete
Advanced Concrete Technology- Properties of Concrete
Bharti Shinde
 
Software Engineering Unit 2 Power Point Presentation AKTU University
Software Engineering Unit 2 Power Point Presentation AKTU UniversitySoftware Engineering Unit 2 Power Point Presentation AKTU University
Software Engineering Unit 2 Power Point Presentation AKTU University
utkarshpandey8299
 
PPT on Grid resilience against Natural disasters.pptx
PPT on Grid resilience against Natural disasters.pptxPPT on Grid resilience against Natural disasters.pptx
PPT on Grid resilience against Natural disasters.pptx
manesumit66
 
1.10 Functions in C++,call by value .pdf
1.10 Functions in C++,call by value .pdf1.10 Functions in C++,call by value .pdf
1.10 Functions in C++,call by value .pdf
VikasNirgude2
 
DIY Gesture Control ESP32 LiteWing Drone using Python
DIY Gesture Control ESP32 LiteWing Drone using  PythonDIY Gesture Control ESP32 LiteWing Drone using  Python
DIY Gesture Control ESP32 LiteWing Drone using Python
CircuitDigest
 
Unit 6 Message Digest Message Digest Message Digest
Unit 6  Message Digest  Message Digest  Message DigestUnit 6  Message Digest  Message Digest  Message Digest
Unit 6 Message Digest Message Digest Message Digest
ChatanBawankar
 
Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.
MdManikurRahman
 
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITSDIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
Sridhar191373
 
Dr. Shivu__Machine Learning-Module 3.pdf
Dr. Shivu__Machine Learning-Module 3.pdfDr. Shivu__Machine Learning-Module 3.pdf
Dr. Shivu__Machine Learning-Module 3.pdf
Dr. Shivashankar
 
THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...
THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...
THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...
ijfcstjournal
 
Advanced Concrete Technology- Properties of Admixtures
Advanced Concrete Technology- Properties of AdmixturesAdvanced Concrete Technology- Properties of Admixtures
Advanced Concrete Technology- Properties of Admixtures
Bharti Shinde
 
Supplier_PFMEA_Workshop_rev 22_04_27.pptx
Supplier_PFMEA_Workshop_rev 22_04_27.pptxSupplier_PFMEA_Workshop_rev 22_04_27.pptx
Supplier_PFMEA_Workshop_rev 22_04_27.pptx
dariojaen1977
 
Salesforce Hackathon Fun Slide for Everyone
Salesforce Hackathon Fun Slide for EveryoneSalesforce Hackathon Fun Slide for Everyone
Salesforce Hackathon Fun Slide for Everyone
ImtiazBinMohiuddin
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdfDr. Shivu___Machine Learning_Module 2pdf
Dr. Shivu___Machine Learning_Module 2pdf
Dr. Shivashankar
 
Java Programming Language: until 2025 and beyond
Java Programming Language: until 2025 and beyondJava Programming Language: until 2025 and beyond
Java Programming Language: until 2025 and beyond
arzu TR
 
BEC602- Module 3-2-Notes.pdf.Vlsi design and testing notes
BEC602- Module 3-2-Notes.pdf.Vlsi design and testing notesBEC602- Module 3-2-Notes.pdf.Vlsi design and testing notes
BEC602- Module 3-2-Notes.pdf.Vlsi design and testing notes
VarshithaP6
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine, Issue 53 / Spring 2025
Better Builder Magazine
 
Advanced Concrete Technology- Properties of Concrete
Advanced Concrete Technology- Properties of ConcreteAdvanced Concrete Technology- Properties of Concrete
Advanced Concrete Technology- Properties of Concrete
Bharti Shinde
 
Software Engineering Unit 2 Power Point Presentation AKTU University
Software Engineering Unit 2 Power Point Presentation AKTU UniversitySoftware Engineering Unit 2 Power Point Presentation AKTU University
Software Engineering Unit 2 Power Point Presentation AKTU University
utkarshpandey8299
 
PPT on Grid resilience against Natural disasters.pptx
PPT on Grid resilience against Natural disasters.pptxPPT on Grid resilience against Natural disasters.pptx
PPT on Grid resilience against Natural disasters.pptx
manesumit66
 
1.10 Functions in C++,call by value .pdf
1.10 Functions in C++,call by value .pdf1.10 Functions in C++,call by value .pdf
1.10 Functions in C++,call by value .pdf
VikasNirgude2
 
DIY Gesture Control ESP32 LiteWing Drone using Python
DIY Gesture Control ESP32 LiteWing Drone using  PythonDIY Gesture Control ESP32 LiteWing Drone using  Python
DIY Gesture Control ESP32 LiteWing Drone using Python
CircuitDigest
 
Unit 6 Message Digest Message Digest Message Digest
Unit 6  Message Digest  Message Digest  Message DigestUnit 6  Message Digest  Message Digest  Message Digest
Unit 6 Message Digest Message Digest Message Digest
ChatanBawankar
 
Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.Department of Environment (DOE) Mix Design with Fly Ash.
Department of Environment (DOE) Mix Design with Fly Ash.
MdManikurRahman
 
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITSDIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
DIGITAL ELECTRONICS: UNIT-III SYNCHRONOUS SEQUENTIAL CIRCUITS
Sridhar191373
 
Dr. Shivu__Machine Learning-Module 3.pdf
Dr. Shivu__Machine Learning-Module 3.pdfDr. Shivu__Machine Learning-Module 3.pdf
Dr. Shivu__Machine Learning-Module 3.pdf
Dr. Shivashankar
 
THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...
THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...
THE RISK ASSESSMENT AND TREATMENT APPROACH IN ORDER TO PROVIDE LAN SECURITY B...
ijfcstjournal
 
Advanced Concrete Technology- Properties of Admixtures
Advanced Concrete Technology- Properties of AdmixturesAdvanced Concrete Technology- Properties of Admixtures
Advanced Concrete Technology- Properties of Admixtures
Bharti Shinde
 
Supplier_PFMEA_Workshop_rev 22_04_27.pptx
Supplier_PFMEA_Workshop_rev 22_04_27.pptxSupplier_PFMEA_Workshop_rev 22_04_27.pptx
Supplier_PFMEA_Workshop_rev 22_04_27.pptx
dariojaen1977
 
Salesforce Hackathon Fun Slide for Everyone
Salesforce Hackathon Fun Slide for EveryoneSalesforce Hackathon Fun Slide for Everyone
Salesforce Hackathon Fun Slide for Everyone
ImtiazBinMohiuddin
 

CG08 - Bresenham’s Line Algorithm Data structure.pdf

  • 1. Computer Graphics CS-443 Lecture 8 “Bresenham’s Line Algorithm” By: Faiz.Ur.Rehman Lecturer in Computer Science [email protected]
  • 2. Index o The Bresenham algorithm o Review o The Big Idea o Deriving The Bresenham Line Algorithm o The Bresenham Line Algorithm o Examples o Tasks o Summary Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 2
  • 3. Objective of the today’s topic • To Understand the basic concept of line drawing algorithm. • To Study that how line is draw on raster display. • To understand a mathematical background of Bresenham’s line algorithm. Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 3
  • 4. The Bresenham Line Algorithm • The Bresenham algorithm is another incremental scan conversion algorithm • The big advantage of this algorithm is that it uses only integer calculations Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 4 Jack Bresenham worked for 27 years at IBM before entering academia. Bresenham developed his famous algorithms at IBM in t h e e a r l y 1 9 6 0 s
  • 5. Review • Point Slope Line Equation: • y = m.x + b • Slope: • m = y2 − y1 / x2 − x1 = Δy / Δx • y-intercept • b = y1 − m.x1 • x-interval • Δx = Δy / m • y-interval • Δy = m Δx Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 5
  • 6. The Big Idea • Move across the x axis in unit intervals and at each step choose between two different y coordinates Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 6 2 3 4 5 2 4 3 5 (xk, yk) (xk+1, yk) (xk+1, yk+1) (Previous) NE (next) E (next) • For example, from position (2, 3) we have to choose between (3, 3) and (3, 4) • We would like the pixel that is closer to the original line
  • 7. Deriving the Bresenham line algorithm • At sample position xk+1 the vertical separations from the mathematical line are labelled dupper and dlower • The y coordinate on the mathematical line at xk+1 is: Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 7 b x m y k + + = ) 1 ( y yk yk+1 xk+1 dlower dupper
  • 8. Deriving the Bresenham line algorithm (cont…) • So, dupper and dlower are given as follows: • and: • We can use these equations to make a simple decision about which pixel is closer to the mathematical line. Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 8 k lower y y d − = k k Lower y b x m d − + + = ) 1 ( y y d k upper − + = ) 1 ( b x m y k k − + − + = ) 1 ( 1
  • 9. Deriving the Bresenham line algorithm (cont…) • This simple decision is based on the difference between the two pixel positions: • Let’s substitute m with ∆y/∆x where ∆x and ∆y are the differences between the end-points: Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 9 1 2 2 ) 1 ( 2 − + − + = − b y x m d d k k upper lower ) ) 1 ( 1 ( ) ) 1 ( ( b x m y y b x m d d k k k k Uper Lower − + − + − − + + = − ) 1 2 2 ) 1 ( 2 ( ) ( − + − +    = −  b y x x y x d d x k k upper lower ) 1 2 ( 2 2 2 −  +  +   −   = b x y y x x y k k c y x x y k k +   −   = 2 2
  • 10. The Bresenham line algorithm • BRESENHAM’S LINE DRAWING ALGORITHM (for |m| < 1.0) 1. Input the two line end-points, storing the left end- point in (x0, y0) 2. Plot the point (x0, y0) 3. Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx) and get the first value for the decision parameter as: 4. At each xk along the line, starting at k = 0, perform the following test. If pk < 0, the next point to plot is (xk+1, yk) and: Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 10 x y p  −  = 2 0 y p p k k  + = + 2 1
  • 11. The Bresenham line algorithm Otherwise, the next point to plot is (xk+1, yk+1) and: 5. Repeat step 4 (Δx – 1) times • The algorithm and derivation above assumes slopes are less than 1. for other slopes we need to adjust the algorithm slightly. Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 11 x y p p k k  −  + = + 2 2 1
  • 12. Example 1 • Let the given end points for the line be (30,20) and (40, 28) • M = dy = y2 – y1 = 28 – 20 = 8 • dx x2 – x1 40 – 30 = 10 • m = 0.8 • dy = 8 and dx = 10 • The initial decision parameter P0 is • P0 = 2dy – dx = 2(8) – 10 = 16 – 10 = 6 • P0 = 6>0, there x and y will be increase with interval one. • The constants 2dy and 2dy-2dx are • 2dy = 2(8) = 16 2dy-2dx = 2(8)- 2(10) =16 – 20 • 2dy = 16 2dy – 2dx = - 4 Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 12
  • 13. Example 1 (cont…) • End points (30,20) (40,28) • dx=x2-x1=40-30=10 dy= y2-y1=28-20=8 • P0=2dy-dx=2X8-10 = 6 >0 pt(31,21) • Pk+1= pk+2dy-2dx= 6+16-20 =2 >0 (32,22) • Pk+1=2+16-20 =-2 <0 (33,22) • Pk+1= pk+2dy =-2+16 = 14 >0 (34,23) • Pk+1= pk+2dy-2dx=14+16-20=10>0 (35,24) • Pk+1=10+16-20=6 >0 (36,25) • Pk+1= 6+16-20=2>0 (37,26) • Pk+1=2+16-20=-2 <0 (38,26) • Pk+1= pk+2dy=-2+16=14>0 (39,27) • Pk+1=pk+2dy-2dx= 14+16-20=10>0 (40,28) Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 13
  • 14. Example 1 (cont…) • The starting point (x0, y0)=(30,20) and the successive pixel positions are given in the following table Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 14 K Pk (Xk+1, Yk+1) 0 6 (31,21) 1 2 32,22 2 -2 33,22 3 14 34,23 4 10 35,24 5 6 36,25 6 2 37,26 7 -2 38,26 8 14 39,27 9 10 40,28
  • 15. Example 2 • We plot the initial point (x0 , y0)=(20,10) and (x1 , y1)= (30,18) • determine successive pixel positions along the line path from the decision parameter as. Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 15 K pk (xk +1, yk +1) K pk (xk +1, yk +1) 0 6 (21,11) 5 6 (26,15) 1 2 (22,12) 6 2 (27,16) 2 -2 (23,12) 7 -2 (28,16) 3 14 (24,13) 8 14 (29,17) 4 10 (25,14) 9 10 (30,18)
  • 18. Task 1 • Consider the line from (5, 8) to (9,11),use general Bresenham’s line algorithm to rasterize this line. Evaluate and tabulate all the steps involved. 18 Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
  • 19. Task 2 • Consider the line from (0, 0) to (-8,-4), use general Bresenham’s line algorithm to rasterize this line. Evaluate and tabulate all the steps involved. 19 Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
  • 20. Bresenham Line Algorithm Summary • The Bresenham line algorithm has the following advantages: • A fast incremental algorithm • Uses only integer calculations • Comparing this to the DDA algorithm, DDA has the following problems: • Accumulation of round-off errors can make the pixelated line drift away from what was intended • The rounding operations and floating-point arithmetic involved are time consuming 20 Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat
  • 21. Assignment No.1 • Explore the Bresenham’s line algorithm procedure (for |m| >1.0) Faiz.Ur.Rehman, Lecturer CS-GPGC Kohat 21