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

DOC
A2 Chapter 5 Study Guide
PPT
Core 3 Modulus 2
PDF
ikh323-06
PPTX
Making t chart
PDF
Worksheet 3 addition & subtraction
PDF
Tugas mtk 1.01
PDF
Digital Differential Analyzer Line Drawing Algorithm
DOC
A2 Chapter 5 Study Guide
Core 3 Modulus 2
ikh323-06
Making t chart
Worksheet 3 addition & subtraction
Tugas mtk 1.01
Digital Differential Analyzer Line Drawing Algorithm

What's hot (20)

PDF
Computing a square root product
PPT
Lesson 5.3 honors
DOCX
University of phoennix mth 209 discussions
PPTX
Bingo 1 precal
PPT
Combined operation
PPT
Vedic Mathematics- Combined operation Sum and Product of Numbers
PDF
Distance book title
PPT
PDF
IIR filter realization using direct form I & II
PPTX
Bingo 1 precal
PPTX
Bingo 1 precal
PPTX
Colour in Mathematics
PPTX
Math is fun!
PPSX
Mb 106 quantitative techniques 7
PPSX
Mb 106 quantitative techniques 4
PPT
Inequalities day 1 worked
PPT
Structures for FIR systems
PPTX
karnaugh maps
PPTX
Multiplying polynomials
PPT
Inequalities day 2 worked
Computing a square root product
Lesson 5.3 honors
University of phoennix mth 209 discussions
Bingo 1 precal
Combined operation
Vedic Mathematics- Combined operation Sum and Product of Numbers
Distance book title
IIR filter realization using direct form I & II
Bingo 1 precal
Bingo 1 precal
Colour in Mathematics
Math is fun!
Mb 106 quantitative techniques 7
Mb 106 quantitative techniques 4
Inequalities day 1 worked
Structures for FIR systems
karnaugh maps
Multiplying polynomials
Inequalities day 2 worked
Ad

Similar to Bresenham Line Drawing Algorithm (20)

DOCX
Coding io1-materials for students-group3
PDF
Open GL T0074 56 sm2
PDF
Unit 2
PDF
Computer graphics notes watermark
PDF
module 1.pdf
PDF
Computer graphics notes
PDF
DOC
COMPUTER GRAPHICS LAB MANUAL
PPT
computer_graphics_line_algorithm in Computer Graphics
PPT
Introduction to Computer Graphics computer
PPT
Introduction to Computer Graphics elements
PPT
Unit I-cg.ppt Introduction to Computer Graphics elements
PPTX
PPTX
computer graphics-C/C++-dancingdollcode
PPTX
lecture 1.pptx
PDF
Cg lab cse-v (1) (1)
DOC
Computer graphics
DOC
Computer graphics
PPTX
Output Primitive and Brenshamas Line.pptx
PPTX
Comuter graphics bresenhams line drawing algorithm
Coding io1-materials for students-group3
Open GL T0074 56 sm2
Unit 2
Computer graphics notes watermark
module 1.pdf
Computer graphics notes
COMPUTER GRAPHICS LAB MANUAL
computer_graphics_line_algorithm in Computer Graphics
Introduction to Computer Graphics computer
Introduction to Computer Graphics elements
Unit I-cg.ppt Introduction to Computer Graphics elements
computer graphics-C/C++-dancingdollcode
lecture 1.pptx
Cg lab cse-v (1) (1)
Computer graphics
Computer graphics
Output Primitive and Brenshamas Line.pptx
Comuter graphics bresenhams line drawing algorithm
Ad

More from Kasun Ranga Wijeweera (20)

PDF
Decorator Design Pattern in C#
PDF
Singleton Design Pattern in C#
PDF
Introduction to Design Patterns
PPTX
Algorithms for Convex Partitioning of a Polygon
PDF
Geometric Transformations II
PDF
Geometric Transformations I
PDF
Introduction to Polygons
PDF
Loops in Visual Basic: Exercises
PDF
Conditional Logic: Exercises
PDF
Getting Started with Visual Basic Programming
PDF
CheckBoxes and RadioButtons
PDF
Variables in Visual Basic Programming
PDF
Loops in Visual Basic Programming
PDF
Conditional Logic in Visual Basic Programming
PDF
Assignment for Variables
PDF
Assignment for Factory Method Design Pattern in C# [ANSWERS]
PDF
Assignment for Events
PDF
Mastering Arrays Assignment
PDF
Arrays in Visual Basic Programming
PDF
An Exercise for Factory Method Design Pattern in C#
Decorator Design Pattern in C#
Singleton Design Pattern in C#
Introduction to Design Patterns
Algorithms for Convex Partitioning of a Polygon
Geometric Transformations II
Geometric Transformations I
Introduction to Polygons
Loops in Visual Basic: Exercises
Conditional Logic: Exercises
Getting Started with Visual Basic Programming
CheckBoxes and RadioButtons
Variables in Visual Basic Programming
Loops in Visual Basic Programming
Conditional Logic in Visual Basic Programming
Assignment for Variables
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Events
Mastering Arrays Assignment
Arrays in Visual Basic Programming
An Exercise for Factory Method Design Pattern in C#

Recently uploaded (20)

PPTX
Presentation - Summer Internship at Samatrix.io_template_2.pptx
PPTX
Human-Computer Interaction for Lecture 1
PPTX
Chapter_05_System Modeling for software engineering
PPTX
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
PPTX
Beige and Black Minimalist Project Deck Presentation (1).pptx
PPTX
AI Tools Revolutionizing Software Development Workflows
PDF
Odoo Construction Management System by CandidRoot
PPTX
SAP Business AI_L1 Overview_EXTERNAL.pptx
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
PPTX
Human-Computer Interaction for Lecture 2
PDF
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
PDF
Cloud Native Aachen Meetup - Aug 21, 2025
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PDF
Mobile App Backend Development with WordPress REST API: The Complete eBook
PDF
infoteam HELLAS company profile 2025 presentation
PPTX
UNIT II: Software design, software .pptx
PDF
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
PPTX
Why 2025 Is the Best Year to Hire Software Developers in India
Presentation - Summer Internship at Samatrix.io_template_2.pptx
Human-Computer Interaction for Lecture 1
Chapter_05_System Modeling for software engineering
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
Beige and Black Minimalist Project Deck Presentation (1).pptx
AI Tools Revolutionizing Software Development Workflows
Odoo Construction Management System by CandidRoot
SAP Business AI_L1 Overview_EXTERNAL.pptx
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
Human-Computer Interaction for Lecture 2
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
Cloud Native Aachen Meetup - Aug 21, 2025
Understanding the Need for Systemic Change in Open Source Through Intersectio...
ROI from Efficient Content & Campaign Management in the Digital Media Industry
Mobile App Backend Development with WordPress REST API: The Complete eBook
infoteam HELLAS company profile 2025 presentation
UNIT II: Software design, software .pptx
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
Why 2025 Is the Best Year to Hire Software Developers in India

Bresenham Line Drawing Algorithm

  • 1. Computer Graphics 1 of 5 Lesson 2: Bresenham Line Drawing Algorithm Author: Kasun Ranga Wijeweera Email: [email protected] 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.