SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
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.

Contenu connexe

Tendances

Computing a square root product
Computing a square root productComputing a square root product
Computing a square root product
TutorMate33
 
Lesson 5.3 honors
Lesson 5.3 honorsLesson 5.3 honors
Lesson 5.3 honors
morrobea
 

Tendances (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
 

Similaire à Bresenham Line Drawing Algorithm

Algebra ii honors study guide
Algebra ii honors study guideAlgebra ii honors study guide
Algebra ii honors study guide
morrobea
 
Algebra ii honors study guide
Algebra ii honors study guideAlgebra ii honors study guide
Algebra ii honors study guide
morrobea
 
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
Wendy Pindah
 

Similaire à 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
 

Plus de Kasun Ranga Wijeweera

Plus de 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#
 

Dernier

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Dernier (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 

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.