SlideShare a Scribd company logo
1 of 5
Download to read offline
Computer Graphics
1 of 5
Lesson 2: Bresenham Line Drawing Algorithm
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 2020 June 19
The screen of a computer is a rectangular grid. A cell in the grid is
called a “pixel”. An example is given below that has 20 × 20 pixels.
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Computer Graphics
2 of 5
Bresenham Line Drawing Algorithm in Step Form for |m| < 1
Note: Let (x1, y1) is the left endpoint, (x2, y2) is the right endpoint,
and m is the gradient of the line segment.
1) Set k = 0.
2) Fill pixel (x[k], y[k]); i.e., fill pixel (x1, y1).
3) Compute p [k] = 2 * dy – dx where dx = x2 – x1 and dy = y2 – y1.
4) If p [k] < 0, fill pixel (x [k] + 1, y [k]) and p [k + 1] = p [k] + 2 * dy.
Otherwise, fill pixel (x [k] + 1, y [k] + 1) and p [k + 1] = p [k] + 2 *
dy – 2 * dx.
5) Set k = k + 1 and go to step 4 if k < dx.
Computer Graphics
3 of 5
Example
Demonstrate drawing a line segment from (2, 3) to (7, 5).
Answer:
5
4
3
2 3 4 5 6 7
k = 0;
SET_PIXEL (2, 3);
5
4
3
2 3 4 5 6 7
dx = 7 – 2 = 5;
dy = 5 – 3 = 2;
p [0] = 2 * 2 – 5 = -1;
p [0] < 0;
SET_PIXEL (3, 3);
5
4
3
2 3 4 5 6 7
Computer Graphics
4 of 5
p [1] = -1 + 2 (2) = 3;
k = 1 < 5;
p [1] ≥ 0;
SET_PIXEL (4, 4);
5
4
3
2 3 4 5 6 7
p [2] = 3 + 2 (2) – 2 (5) = -3;
k = 2 < 5;
p [2] < 0;
SET_PIXEL (5, 4);
5
4
3
2 3 4 5 6 7
p [3] = -3 + 2 (2) = 1;
k = 3 < 5;
Computer Graphics
5 of 5
p [3] ≥ 0;
SET_PIXEL (6, 5);
5
4
3
2 3 4 5 6 7
p [4] = 1 + 2 (2) – 2 (5) = -5;
k = 4 < 5;
p [4] < 0;
SET_PIXEL (7, 5);
5
4
3
2 3 4 5 6 7
p [5] = -5 + 2 (2) = -1;
k = 5 ≥ 5.

More Related Content

What's hot

Computing a square root product
Computing a square root productComputing a square root product
Computing a square root productTutorMate33
 
Lesson 5.3 honors
Lesson 5.3 honorsLesson 5.3 honors
Lesson 5.3 honorsmorrobea
 
University of phoennix mth 209 discussions
University of phoennix mth 209  discussionsUniversity of phoennix mth 209  discussions
University of phoennix mth 209 discussionsleesa marteen
 
Bingo 1 precal
Bingo 1 precalBingo 1 precal
Bingo 1 precalezeash17
 
Vedic Mathematics- Combined operation Sum and Product of Numbers
Vedic Mathematics- Combined operation Sum and Product of NumbersVedic Mathematics- Combined operation Sum and Product of Numbers
Vedic Mathematics- Combined operation Sum and Product of Numbersculturalcomputingindia
 
Distance book title
Distance  book titleDistance  book title
Distance book titleNadeem Uddin
 
IIR filter realization using direct form I & II
IIR filter realization using direct form I & IIIIR filter realization using direct form I & II
IIR filter realization using direct form I & IISarang Joshi
 
Bingo 1 precal
Bingo 1 precalBingo 1 precal
Bingo 1 precalezeash17
 
Bingo 1 precal
Bingo 1 precalBingo 1 precal
Bingo 1 precalezeash17
 
Colour in Mathematics
Colour in Mathematics Colour in Mathematics
Colour in Mathematics Colleen Young
 
Mb 106 quantitative techniques 7
Mb 106 quantitative techniques 7Mb 106 quantitative techniques 7
Mb 106 quantitative techniques 7KrishnaRoy45
 
Mb 106 quantitative techniques 4
Mb 106 quantitative techniques 4Mb 106 quantitative techniques 4
Mb 106 quantitative techniques 4KrishnaRoy45
 
Inequalities day 1 worked
Inequalities day 1 workedInequalities day 1 worked
Inequalities day 1 workedJonna Ramsey
 
Structures for FIR systems
Structures for FIR systemsStructures for FIR systems
Structures for FIR systemsChandan Taluja
 
Multiplying polynomials
Multiplying polynomialsMultiplying polynomials
Multiplying polynomialsQueenPinky644
 
Inequalities day 2 worked
Inequalities day 2 workedInequalities day 2 worked
Inequalities day 2 workedJonna Ramsey
 

What's hot (20)

Computing a square root product
Computing a square root productComputing a square root product
Computing a square root product
 
Lesson 5.3 honors
Lesson 5.3 honorsLesson 5.3 honors
Lesson 5.3 honors
 
University of phoennix mth 209 discussions
University of phoennix mth 209  discussionsUniversity of phoennix mth 209  discussions
University of phoennix mth 209 discussions
 
Bingo 1 precal
Bingo 1 precalBingo 1 precal
Bingo 1 precal
 
Combined operation
Combined operationCombined operation
Combined operation
 
Vedic Mathematics- Combined operation Sum and Product of Numbers
Vedic Mathematics- Combined operation Sum and Product of NumbersVedic Mathematics- Combined operation Sum and Product of Numbers
Vedic Mathematics- Combined operation Sum and Product of Numbers
 
Distance book title
Distance  book titleDistance  book title
Distance book title
 
Chptr 1 review
Chptr 1 reviewChptr 1 review
Chptr 1 review
 
IIR filter realization using direct form I & II
IIR filter realization using direct form I & IIIIR filter realization using direct form I & II
IIR filter realization using direct form I & II
 
Bingo 1 precal
Bingo 1 precalBingo 1 precal
Bingo 1 precal
 
Bingo 1 precal
Bingo 1 precalBingo 1 precal
Bingo 1 precal
 
Colour in Mathematics
Colour in Mathematics Colour in Mathematics
Colour in Mathematics
 
Math is fun!
Math is fun!Math is fun!
Math is fun!
 
Mb 106 quantitative techniques 7
Mb 106 quantitative techniques 7Mb 106 quantitative techniques 7
Mb 106 quantitative techniques 7
 
Mb 106 quantitative techniques 4
Mb 106 quantitative techniques 4Mb 106 quantitative techniques 4
Mb 106 quantitative techniques 4
 
Inequalities day 1 worked
Inequalities day 1 workedInequalities day 1 worked
Inequalities day 1 worked
 
Structures for FIR systems
Structures for FIR systemsStructures for FIR systems
Structures for FIR systems
 
karnaugh maps
karnaugh mapskarnaugh maps
karnaugh maps
 
Multiplying polynomials
Multiplying polynomialsMultiplying polynomials
Multiplying polynomials
 
Inequalities day 2 worked
Inequalities day 2 workedInequalities day 2 worked
Inequalities day 2 worked
 

Similar to Bresenham Line Drawing Algorithm

Algebra ii honors study guide
Algebra ii honors study guideAlgebra ii honors study guide
Algebra ii honors study guidemorrobea
 
Algebra ii honors study guide
Algebra ii honors study guideAlgebra ii honors study guide
Algebra ii honors study guidemorrobea
 
College algebra in context 5th edition harshbarger solutions manual
College algebra in context 5th edition harshbarger solutions manualCollege algebra in context 5th edition harshbarger solutions manual
College algebra in context 5th edition harshbarger solutions manualAnnuzzi19
 
Chapter_3_Gate-Level_Minimization.ppt
Chapter_3_Gate-Level_Minimization.pptChapter_3_Gate-Level_Minimization.ppt
Chapter_3_Gate-Level_Minimization.pptMdTahsinAmin2
 
35182797 additional-mathematics-form-4-and-5-notes
35182797 additional-mathematics-form-4-and-5-notes35182797 additional-mathematics-form-4-and-5-notes
35182797 additional-mathematics-form-4-and-5-notesWendy Pindah
 
Who wants to pass this course
Who wants to pass this courseWho wants to pass this course
Who wants to pass this courseadvancedfunctions
 
12 cbse-maths-2014-solution set 1
12 cbse-maths-2014-solution set 1 12 cbse-maths-2014-solution set 1
12 cbse-maths-2014-solution set 1 vandna123
 
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...Jhonatan Minchán
 
Sol mat haeussler_by_priale
Sol mat haeussler_by_prialeSol mat haeussler_by_priale
Sol mat haeussler_by_prialeJeff Chasi
 
31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manual31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manualMahrukh Khalid
 
Solucionario de matemáticas para administación y economia
Solucionario de matemáticas para administación y economiaSolucionario de matemáticas para administación y economia
Solucionario de matemáticas para administación y economiaLuis Perez Anampa
 
Non Deterministic and Deterministic Problems
Non Deterministic and Deterministic Problems Non Deterministic and Deterministic Problems
Non Deterministic and Deterministic Problems Scandala Tamang
 
1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numerosBea Marfer
 

Similar to Bresenham Line Drawing Algorithm (20)

Algebra ii honors study guide
Algebra ii honors study guideAlgebra ii honors study guide
Algebra ii honors study guide
 
Algebra ii honors study guide
Algebra ii honors study guideAlgebra ii honors study guide
Algebra ii honors study guide
 
Set 1 mawar
Set 1 mawarSet 1 mawar
Set 1 mawar
 
College algebra in context 5th edition harshbarger solutions manual
College algebra in context 5th edition harshbarger solutions manualCollege algebra in context 5th edition harshbarger solutions manual
College algebra in context 5th edition harshbarger solutions manual
 
lecture 1.pptx
lecture 1.pptxlecture 1.pptx
lecture 1.pptx
 
Chapter_3_Gate-Level_Minimization.ppt
Chapter_3_Gate-Level_Minimization.pptChapter_3_Gate-Level_Minimization.ppt
Chapter_3_Gate-Level_Minimization.ppt
 
35182797 additional-mathematics-form-4-and-5-notes
35182797 additional-mathematics-form-4-and-5-notes35182797 additional-mathematics-form-4-and-5-notes
35182797 additional-mathematics-form-4-and-5-notes
 
Who wants to pass this course
Who wants to pass this courseWho wants to pass this course
Who wants to pass this course
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
EPCA_MODULE-2.pptx
EPCA_MODULE-2.pptxEPCA_MODULE-2.pptx
EPCA_MODULE-2.pptx
 
12 cbse-maths-2014-solution set 1
12 cbse-maths-2014-solution set 1 12 cbse-maths-2014-solution set 1
12 cbse-maths-2014-solution set 1
 
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
Ernest f. haeussler, richard s. paul y richard j. wood. matemáticas para admi...
 
Sol mat haeussler_by_priale
Sol mat haeussler_by_prialeSol mat haeussler_by_priale
Sol mat haeussler_by_priale
 
31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manual31350052 introductory-mathematical-analysis-textbook-solution-manual
31350052 introductory-mathematical-analysis-textbook-solution-manual
 
Solucionario de matemáticas para administación y economia
Solucionario de matemáticas para administación y economiaSolucionario de matemáticas para administación y economia
Solucionario de matemáticas para administación y economia
 
Negative numbers
Negative numbersNegative numbers
Negative numbers
 
Non Deterministic and Deterministic Problems
Non Deterministic and Deterministic Problems Non Deterministic and Deterministic Problems
Non Deterministic and Deterministic Problems
 
Skills In Add Maths
Skills In Add MathsSkills In Add Maths
Skills In Add Maths
 
Indices
IndicesIndices
Indices
 
1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros
 

More from Kasun Ranga Wijeweera

Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonKasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingKasun Ranga Wijeweera
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic ProgrammingKasun Ranga Wijeweera
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingKasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Kasun Ranga Wijeweera
 
An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#Kasun Ranga Wijeweera
 

More from Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 
Arrays in Visual Basic Programming
Arrays in Visual Basic ProgrammingArrays in Visual Basic Programming
Arrays in Visual Basic Programming
 
An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

Bresenham Line Drawing Algorithm

  • 1. Computer Graphics 1 of 5 Lesson 2: Bresenham Line Drawing Algorithm Author: Kasun Ranga Wijeweera Email: krw19870829@gmail.com Date: 2020 June 19 The screen of a computer is a rectangular grid. A cell in the grid is called a “pixel”. An example is given below that has 20 × 20 pixels. 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  • 2. Computer Graphics 2 of 5 Bresenham Line Drawing Algorithm in Step Form for |m| < 1 Note: Let (x1, y1) is the left endpoint, (x2, y2) is the right endpoint, and m is the gradient of the line segment. 1) Set k = 0. 2) Fill pixel (x[k], y[k]); i.e., fill pixel (x1, y1). 3) Compute p [k] = 2 * dy – dx where dx = x2 – x1 and dy = y2 – y1. 4) If p [k] < 0, fill pixel (x [k] + 1, y [k]) and p [k + 1] = p [k] + 2 * dy. Otherwise, fill pixel (x [k] + 1, y [k] + 1) and p [k + 1] = p [k] + 2 * dy – 2 * dx. 5) Set k = k + 1 and go to step 4 if k < dx.
  • 3. Computer Graphics 3 of 5 Example Demonstrate drawing a line segment from (2, 3) to (7, 5). Answer: 5 4 3 2 3 4 5 6 7 k = 0; SET_PIXEL (2, 3); 5 4 3 2 3 4 5 6 7 dx = 7 – 2 = 5; dy = 5 – 3 = 2; p [0] = 2 * 2 – 5 = -1; p [0] < 0; SET_PIXEL (3, 3); 5 4 3 2 3 4 5 6 7
  • 4. Computer Graphics 4 of 5 p [1] = -1 + 2 (2) = 3; k = 1 < 5; p [1] ≥ 0; SET_PIXEL (4, 4); 5 4 3 2 3 4 5 6 7 p [2] = 3 + 2 (2) – 2 (5) = -3; k = 2 < 5; p [2] < 0; SET_PIXEL (5, 4); 5 4 3 2 3 4 5 6 7 p [3] = -3 + 2 (2) = 1; k = 3 < 5;
  • 5. Computer Graphics 5 of 5 p [3] ≥ 0; SET_PIXEL (6, 5); 5 4 3 2 3 4 5 6 7 p [4] = 1 + 2 (2) – 2 (5) = -5; k = 4 < 5; p [4] < 0; SET_PIXEL (7, 5); 5 4 3 2 3 4 5 6 7 p [5] = -5 + 2 (2) = -1; k = 5 ≥ 5.