SlideShare a Scribd company logo
Appendix: Derivation of Bresenham’s line algorithm
© E Claridge, School of Computer Science, The University of Birmingham
DERIVATION OF THE BRESENHAM’S LINE ALGORITHM
Assumptions:
● input: line endpoints at (X1,Y1) and (X2, Y2)
● X1 < X2
● line slope ≤ 45o
, i.e. 0 < m ≤ 1
● x coordinate is incremented in steps of 1, y coordinate is computed
● generic line equation: y = mx + b
x x +1i i
y i
y +1i
y = mx + b
y
d1
d2
Derivation
Assume that we already have a location of pixel ( xi, yi) and have plotted it. The question is,
what is the location of the next pixel.
Geometric location of the line at x-coordinate xi+1 = xi + 1 is:
y = m(xi + 1 ) + b (1)
where:
m = ∆y / ∆x (slope) (2)
b – intercept
∆x = X2 – X1 (from the assumption above that X1 < X2 ) (3)
∆y = Y2 – Y1
Define:
d1 = y – yi = m(xi + 1 ) + b - yi
d2 = ( yi + 1 ) - y = yi + 1 - m(xi + 1 ) - b
Calculate:
d1 – d2 = m(xi + 1 ) + b - yi - yi – 1 + m(xi + 1 ) + b
= 2m(xi + 1 ) – 2yi + 2b – 1 (4)
if d1 – d2 < 0 then yi+1 ← yi (5)
if d1 – d2 > 0 then yi+1 ← yi + 1 (6)
We want integer calculations in the loop, but m is not an integer. Looking at definition of m
(m = ∆y / ∆x) we see that if we multiply m by ∆x, we shall remove the denominator and
hence the floating point number.
Appendix: Derivation of Bresenham’s line algorithm
© E Claridge, School of Computer Science, The University of Birmingham
For this purpose, let us multiply the difference ( d1 - d2 ) by ∆x and call it pi:
pi = ∆x( d1 – d2)
The sign of pi is the same as the sign of d1 – d2, because of the assumption (3).
Expand pi:
pi = ∆x( d1 – d2)
= ∆x[ 2m(xi + 1 ) – 2yi + 2b – 1 ] from (4)
= ∆x[ 2 ⋅ (∆y / ∆x ) ⋅ (xi + 1 ) – 2yi + 2b – 1 ] from (2)
= 2⋅∆y⋅ (xi + 1 ) – 2⋅∆x⋅yi + 2⋅∆x⋅b – ∆x result of multiplication by ∆x
= 2⋅∆y⋅xi + 2⋅∆y – 2⋅∆x⋅yi + 2⋅∆x⋅b – ∆x
= 2⋅∆y⋅xi– 2⋅∆x⋅yi + 2⋅∆y + 2⋅∆x⋅b – ∆x (7)
Note that the underlined part is constant (it does not change during iteration), we call it c, i.e.
c = 2⋅∆y + 2⋅∆x⋅b – ∆x
Hence we can write an expression for pi as:
pi = 2⋅∆y⋅xi– 2⋅∆x⋅yi + c (8)
Because the sign of pi is the same as the sign of d1 – d2, we could use it inside the loop to
decide whether to select pixel at (xi + 1, yi ) or at (xi + 1, yi +1). Note that the loop will only
include integer arithmetic. There are now 6 multiplications, two additions and one selection in
each turn of the loop.
However, we can do better than this, by defining pi recursively.
pi+1 = 2⋅∆y⋅xi+1– 2⋅∆x⋅yi+1 + c from (8)
pi+1 – pi = 2⋅∆y⋅xi+1– 2⋅∆x⋅yi+1 + c
- (2⋅∆y⋅xi – 2⋅∆x⋅yi + c )
= 2∆y ⋅ (xi+1 – xi) – 2∆x ⋅ (yi+1 – yi) xi+1 – xi = 1 always
pi+1 – pi = 2∆y – 2∆x ⋅ (yi+1 – yi)
Recursive definition for pi:
pi+1 = pi + 2∆y – 2∆x ⋅ (yi+1 – yi)
If you now recall the way we construct the line pixel by pixel, you will realise that the
underlined expression: yi+1 – yi can be either 0 ( when the next pixel is plotted at the same y-
coordinate, i.e. d1 – d2 < 0 from (5)); or 1 ( when the next pixel is plotted at the next y-
coordinate, i.e. d1 – d2 > 0 from (6)). Therefore the final recursive definition for pi will be
based on choice, as follows (remember that the sign of pi is the same as the sign of d1 – d2):
Appendix: Derivation of Bresenham’s line algorithm
© E Claridge, School of Computer Science, The University of Birmingham
if pi < 0, pi+1 = pi + 2∆y because 2∆x ⋅ (yi+1 – yi) = 0
if pi > 0, pi+1 = pi + 2∆y – 2∆x because (yi+1 – yi) = 1
At this stage the basic algorithm is defined. We only need to calculate the initial value for
parameter po.
pi = 2⋅∆y⋅xi– 2⋅∆x⋅yi + 2⋅∆y + 2⋅∆x⋅b – ∆x from (7)
p0 = 2⋅∆y⋅x0– 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅b – ∆x (9)
For the initial point on the line:
y0 = mx0 + b
therefore
b = y0 – (∆y/∆x) ⋅ x0
Substituting the above for b in (9)we get:
p0 = 2⋅∆y⋅x0– 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅ [ y0 – (∆y/∆x) ⋅ x0 ] – ∆x
= 2⋅∆y⋅x0 – 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅y0 – 2∆x⋅ (∆y/∆x) ⋅ x0 – ∆x simplify
= 2⋅∆y⋅x0 – 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅y0 – 2∆y⋅x0 – ∆x regroup
= 2⋅∆y⋅x0 – 2∆y⋅x0 – 2⋅∆x⋅y0 + 2∆x⋅y0 + 2⋅∆y – ∆x simplify
= 2⋅∆y – ∆x
We can now write an outline of the complete algorithm.
Algorithm
1. Input line endpoints, (X1,Y1) and (X2, Y2)
2. Calculate constants:
∆x = X2 – X1
∆y = Y2 – Y1
2∆y
2∆y – ∆x
3. Assign value to the starting parameters:
k = 0
p0 = 2∆y – ∆x
4. Plot the pixel at ((X1,Y1)
5. For each integer x-coordinate, xk, along the line
if pk < 0 plot pixel at ( xk + 1, yk )
pk+1 = pk + 2∆y (note that 2∆y is a pre-computed constant)
else plot pixel at ( xk + 1, yk + 1 )
pk+1 = pk + 2∆y – 2∆x
(note that 2∆y – 2∆x is a pre-computed constant)
increment k
while xk < X2

More Related Content

What's hot

Integration SPM
Integration SPMIntegration SPM
Integration SPM
Hanini Hamsan
 
Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
Praveen Kumar
 
Asymptotes | WORKING PRINCIPLE OF ASYMPTOTES
Asymptotes | WORKING PRINCIPLE OF ASYMPTOTESAsymptotes | WORKING PRINCIPLE OF ASYMPTOTES
Asymptotes | WORKING PRINCIPLE OF ASYMPTOTES
NITESH POONIA
 
Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1
Debora Elluisa Manurung
 
Transforming Quadratic functions from General Form to Standard Form
Transforming Quadratic functions from General Form to Standard FormTransforming Quadratic functions from General Form to Standard Form
Transforming Quadratic functions from General Form to Standard Form
Ivy Estrella
 
Transforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard FormTransforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard Form
Ivy Estrella
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
Mohammad Sadiq
 
Complex Numbers 1 - Math Academy - JC H2 maths A levels
Complex Numbers 1 - Math Academy - JC H2 maths A levelsComplex Numbers 1 - Math Academy - JC H2 maths A levels
Complex Numbers 1 - Math Academy - JC H2 maths A levels
Math Academy Singapore
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Saikrishna Tanguturu
 
Expanding Binomial Brackets
Expanding Binomial BracketsExpanding Binomial Brackets
Expanding Binomial Brackets
Passy World
 
Matdis 3.4
Matdis 3.4Matdis 3.4
Matdis 3.4
Claudia Primasiwi
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functions
Tarun Gehlot
 
Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.
Mohd Arif
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
Taher Barodawala
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
Kumar
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
Mohd Arif
 
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
 
Recurrence
RecurrenceRecurrence
Line circle draw
Line circle drawLine circle draw
Line circle draw
Praveen Kumar
 
Logic Design - Chapter 3: Boolean Algebra
Logic Design - Chapter 3: Boolean AlgebraLogic Design - Chapter 3: Boolean Algebra
Logic Design - Chapter 3: Boolean Algebra
Gouda Mando
 

What's hot (20)

Integration SPM
Integration SPMIntegration SPM
Integration SPM
 
Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
 
Asymptotes | WORKING PRINCIPLE OF ASYMPTOTES
Asymptotes | WORKING PRINCIPLE OF ASYMPTOTESAsymptotes | WORKING PRINCIPLE OF ASYMPTOTES
Asymptotes | WORKING PRINCIPLE OF ASYMPTOTES
 
Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1
 
Transforming Quadratic functions from General Form to Standard Form
Transforming Quadratic functions from General Form to Standard FormTransforming Quadratic functions from General Form to Standard Form
Transforming Quadratic functions from General Form to Standard Form
 
Transforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard FormTransforming Quadratic Functions from General Form to Standard Form
Transforming Quadratic Functions from General Form to Standard Form
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Complex Numbers 1 - Math Academy - JC H2 maths A levels
Complex Numbers 1 - Math Academy - JC H2 maths A levelsComplex Numbers 1 - Math Academy - JC H2 maths A levels
Complex Numbers 1 - Math Academy - JC H2 maths A levels
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 
Expanding Binomial Brackets
Expanding Binomial BracketsExpanding Binomial Brackets
Expanding Binomial Brackets
 
Matdis 3.4
Matdis 3.4Matdis 3.4
Matdis 3.4
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functions
 
Circle drawing algo.
Circle drawing algo.Circle drawing algo.
Circle drawing algo.
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
Computer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmComputer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithm
 
Recurrence
RecurrenceRecurrence
Recurrence
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
Logic Design - Chapter 3: Boolean Algebra
Logic Design - Chapter 3: Boolean AlgebraLogic Design - Chapter 3: Boolean Algebra
Logic Design - Chapter 3: Boolean Algebra
 

Viewers also liked

наоми
наоминаоми
Unit D - CSCI 64
Unit D - CSCI 64Unit D - CSCI 64
Unit D - CSCI 64
dpd
 
師父(簡體版) 街头生意经:Mba课堂不会教你的
師父(簡體版) 街头生意经:Mba课堂不会教你的師父(簡體版) 街头生意经:Mba课堂不会教你的
師父(簡體版) 街头生意经:Mba课堂不会教你的
欣儀 林
 
PennDOT Management Plan for Historic Metal Truss Bridges
PennDOT Management Plan for Historic Metal Truss BridgesPennDOT Management Plan for Historic Metal Truss Bridges
PennDOT Management Plan for Historic Metal Truss Bridges
preservationcombination
 
Windows 7 @Microsoft CTD
Windows 7 @Microsoft CTDWindows 7 @Microsoft CTD
Windows 7 @Microsoft CTD
Abhishek Sharma
 
CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»
CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»
CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»
telosaes
 
Sanità italiana. È tempo di un check up!
Sanità italiana. È tempo di un check up!Sanità italiana. È tempo di un check up!
Sanità italiana. È tempo di un check up!
telosaes
 
BA 15 Chapter 7
BA 15 Chapter 7BA 15 Chapter 7
BA 15 Chapter 7
dpd
 
dda algorithm
dda  algorithmdda  algorithm
dda algorithm
774474
 
Bhavani Resume(1)
Bhavani Resume(1)Bhavani Resume(1)
Bhavani Resume(1)
bhavani lakhavath
 
Profesiones
ProfesionesProfesiones
Profesiones
inmaruiz8
 
BA 15 Chapter 10
BA 15 Chapter 10BA 15 Chapter 10
BA 15 Chapter 10
dpd
 
La civilización azteca y las manifestaciones artisticas de la antigua América...
La civilización azteca y las manifestaciones artisticas de la antigua América...La civilización azteca y las manifestaciones artisticas de la antigua América...
La civilización azteca y las manifestaciones artisticas de la antigua América...Fernando de los Ángeles
 
Computer keyboard
Computer keyboardComputer keyboard
Computer keyboard
Cheneta Kenny Calvo
 
CCC PT Faculty Unemployment Benefits
CCC PT Faculty Unemployment BenefitsCCC PT Faculty Unemployment Benefits
CCC PT Faculty Unemployment Benefits
dpd
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
Mohd Arif
 

Viewers also liked (17)

наоми
наоминаоми
наоми
 
Unit D - CSCI 64
Unit D - CSCI 64Unit D - CSCI 64
Unit D - CSCI 64
 
師父(簡體版) 街头生意经:Mba课堂不会教你的
師父(簡體版) 街头生意经:Mba课堂不会教你的師父(簡體版) 街头生意经:Mba课堂不会教你的
師父(簡體版) 街头生意经:Mba课堂不会教你的
 
PennDOT Management Plan for Historic Metal Truss Bridges
PennDOT Management Plan for Historic Metal Truss BridgesPennDOT Management Plan for Historic Metal Truss Bridges
PennDOT Management Plan for Historic Metal Truss Bridges
 
Windows 7 @Microsoft CTD
Windows 7 @Microsoft CTDWindows 7 @Microsoft CTD
Windows 7 @Microsoft CTD
 
CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»
CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»
CASSAZIONE (2014): «NON È UN’INGIURIA DIRE ALLA SUOCERA CHE È UNA VIPERA»
 
Sanità italiana. È tempo di un check up!
Sanità italiana. È tempo di un check up!Sanità italiana. È tempo di un check up!
Sanità italiana. È tempo di un check up!
 
BA 15 Chapter 7
BA 15 Chapter 7BA 15 Chapter 7
BA 15 Chapter 7
 
dda algorithm
dda  algorithmdda  algorithm
dda algorithm
 
Bhavani Resume(1)
Bhavani Resume(1)Bhavani Resume(1)
Bhavani Resume(1)
 
Profesiones
ProfesionesProfesiones
Profesiones
 
BA 15 Chapter 10
BA 15 Chapter 10BA 15 Chapter 10
BA 15 Chapter 10
 
La civilización azteca y las manifestaciones artisticas de la antigua América...
La civilización azteca y las manifestaciones artisticas de la antigua América...La civilización azteca y las manifestaciones artisticas de la antigua América...
La civilización azteca y las manifestaciones artisticas de la antigua América...
 
Computer keyboard
Computer keyboardComputer keyboard
Computer keyboard
 
CCC PT Faculty Unemployment Benefits
CCC PT Faculty Unemployment BenefitsCCC PT Faculty Unemployment Benefits
CCC PT Faculty Unemployment Benefits
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 

Similar to Bresenham derivation

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
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
V Tripathi
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
NaveenaKarthik3
 
Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)
Fatini Adnan
 
Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01
Asad Bukhari
 
Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01
Nur Kamila
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
Roziq Bahtiar
 
C2 st lecture 6 handout
C2 st lecture 6 handoutC2 st lecture 6 handout
C2 st lecture 6 handout
fatima d
 
Integration
IntegrationIntegration
Integration
SharingIsCaring1000
 
Maths 301 key_sem_1_2009_2010
Maths 301 key_sem_1_2009_2010Maths 301 key_sem_1_2009_2010
Maths 301 key_sem_1_2009_2010
Yanbu Industrial College
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
PrathimaBaliga
 
Mathematics 8 Linear Functions
Mathematics 8 Linear FunctionsMathematics 8 Linear Functions
Mathematics 8 Linear Functions
Juan Miguel Palero
 
Module 1 linear functions
Module 1   linear functionsModule 1   linear functions
Module 1 linear functions
dionesioable
 
Calculus Final Exam
Calculus Final ExamCalculus Final Exam
Calculus Final Exam
Kuan-Lun Wang
 
1.1_The_Definite_Integral.pdf odjoqwddoio
1.1_The_Definite_Integral.pdf odjoqwddoio1.1_The_Definite_Integral.pdf odjoqwddoio
1.1_The_Definite_Integral.pdf odjoqwddoio
NoorYassinHJamel
 
Quadratic Function Presentation
Quadratic Function PresentationQuadratic Function Presentation
Quadratic Function Presentation
RyanWatt
 
C2 st lecture 2 handout
C2 st lecture 2 handoutC2 st lecture 2 handout
C2 st lecture 2 handout
fatima d
 
Chapter 1 (math 1)
Chapter 1 (math 1)Chapter 1 (math 1)
Chapter 1 (math 1)
Amr Mohamed
 
整卷
整卷整卷
Bahan ajar kalkulus integral
Bahan ajar kalkulus integralBahan ajar kalkulus integral
Bahan ajar kalkulus integral
grand_livina_good
 

Similar to Bresenham derivation (20)

Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptx
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)Additional Mathematics form 4 (formula)
Additional Mathematics form 4 (formula)
 
Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01
 
Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01Spm add-maths-formula-list-form4-091022090639-phpapp01
Spm add-maths-formula-list-form4-091022090639-phpapp01
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
C2 st lecture 6 handout
C2 st lecture 6 handoutC2 st lecture 6 handout
C2 st lecture 6 handout
 
Integration
IntegrationIntegration
Integration
 
Maths 301 key_sem_1_2009_2010
Maths 301 key_sem_1_2009_2010Maths 301 key_sem_1_2009_2010
Maths 301 key_sem_1_2009_2010
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Mathematics 8 Linear Functions
Mathematics 8 Linear FunctionsMathematics 8 Linear Functions
Mathematics 8 Linear Functions
 
Module 1 linear functions
Module 1   linear functionsModule 1   linear functions
Module 1 linear functions
 
Calculus Final Exam
Calculus Final ExamCalculus Final Exam
Calculus Final Exam
 
1.1_The_Definite_Integral.pdf odjoqwddoio
1.1_The_Definite_Integral.pdf odjoqwddoio1.1_The_Definite_Integral.pdf odjoqwddoio
1.1_The_Definite_Integral.pdf odjoqwddoio
 
Quadratic Function Presentation
Quadratic Function PresentationQuadratic Function Presentation
Quadratic Function Presentation
 
C2 st lecture 2 handout
C2 st lecture 2 handoutC2 st lecture 2 handout
C2 st lecture 2 handout
 
Chapter 1 (math 1)
Chapter 1 (math 1)Chapter 1 (math 1)
Chapter 1 (math 1)
 
整卷
整卷整卷
整卷
 
Bahan ajar kalkulus integral
Bahan ajar kalkulus integralBahan ajar kalkulus integral
Bahan ajar kalkulus integral
 

Recently uploaded

Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 

Recently uploaded (20)

Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 

Bresenham derivation

  • 1. Appendix: Derivation of Bresenham’s line algorithm © E Claridge, School of Computer Science, The University of Birmingham DERIVATION OF THE BRESENHAM’S LINE ALGORITHM Assumptions: ● input: line endpoints at (X1,Y1) and (X2, Y2) ● X1 < X2 ● line slope ≤ 45o , i.e. 0 < m ≤ 1 ● x coordinate is incremented in steps of 1, y coordinate is computed ● generic line equation: y = mx + b x x +1i i y i y +1i y = mx + b y d1 d2 Derivation Assume that we already have a location of pixel ( xi, yi) and have plotted it. The question is, what is the location of the next pixel. Geometric location of the line at x-coordinate xi+1 = xi + 1 is: y = m(xi + 1 ) + b (1) where: m = ∆y / ∆x (slope) (2) b – intercept ∆x = X2 – X1 (from the assumption above that X1 < X2 ) (3) ∆y = Y2 – Y1 Define: d1 = y – yi = m(xi + 1 ) + b - yi d2 = ( yi + 1 ) - y = yi + 1 - m(xi + 1 ) - b Calculate: d1 – d2 = m(xi + 1 ) + b - yi - yi – 1 + m(xi + 1 ) + b = 2m(xi + 1 ) – 2yi + 2b – 1 (4) if d1 – d2 < 0 then yi+1 ← yi (5) if d1 – d2 > 0 then yi+1 ← yi + 1 (6) We want integer calculations in the loop, but m is not an integer. Looking at definition of m (m = ∆y / ∆x) we see that if we multiply m by ∆x, we shall remove the denominator and hence the floating point number.
  • 2. Appendix: Derivation of Bresenham’s line algorithm © E Claridge, School of Computer Science, The University of Birmingham For this purpose, let us multiply the difference ( d1 - d2 ) by ∆x and call it pi: pi = ∆x( d1 – d2) The sign of pi is the same as the sign of d1 – d2, because of the assumption (3). Expand pi: pi = ∆x( d1 – d2) = ∆x[ 2m(xi + 1 ) – 2yi + 2b – 1 ] from (4) = ∆x[ 2 ⋅ (∆y / ∆x ) ⋅ (xi + 1 ) – 2yi + 2b – 1 ] from (2) = 2⋅∆y⋅ (xi + 1 ) – 2⋅∆x⋅yi + 2⋅∆x⋅b – ∆x result of multiplication by ∆x = 2⋅∆y⋅xi + 2⋅∆y – 2⋅∆x⋅yi + 2⋅∆x⋅b – ∆x = 2⋅∆y⋅xi– 2⋅∆x⋅yi + 2⋅∆y + 2⋅∆x⋅b – ∆x (7) Note that the underlined part is constant (it does not change during iteration), we call it c, i.e. c = 2⋅∆y + 2⋅∆x⋅b – ∆x Hence we can write an expression for pi as: pi = 2⋅∆y⋅xi– 2⋅∆x⋅yi + c (8) Because the sign of pi is the same as the sign of d1 – d2, we could use it inside the loop to decide whether to select pixel at (xi + 1, yi ) or at (xi + 1, yi +1). Note that the loop will only include integer arithmetic. There are now 6 multiplications, two additions and one selection in each turn of the loop. However, we can do better than this, by defining pi recursively. pi+1 = 2⋅∆y⋅xi+1– 2⋅∆x⋅yi+1 + c from (8) pi+1 – pi = 2⋅∆y⋅xi+1– 2⋅∆x⋅yi+1 + c - (2⋅∆y⋅xi – 2⋅∆x⋅yi + c ) = 2∆y ⋅ (xi+1 – xi) – 2∆x ⋅ (yi+1 – yi) xi+1 – xi = 1 always pi+1 – pi = 2∆y – 2∆x ⋅ (yi+1 – yi) Recursive definition for pi: pi+1 = pi + 2∆y – 2∆x ⋅ (yi+1 – yi) If you now recall the way we construct the line pixel by pixel, you will realise that the underlined expression: yi+1 – yi can be either 0 ( when the next pixel is plotted at the same y- coordinate, i.e. d1 – d2 < 0 from (5)); or 1 ( when the next pixel is plotted at the next y- coordinate, i.e. d1 – d2 > 0 from (6)). Therefore the final recursive definition for pi will be based on choice, as follows (remember that the sign of pi is the same as the sign of d1 – d2):
  • 3. Appendix: Derivation of Bresenham’s line algorithm © E Claridge, School of Computer Science, The University of Birmingham if pi < 0, pi+1 = pi + 2∆y because 2∆x ⋅ (yi+1 – yi) = 0 if pi > 0, pi+1 = pi + 2∆y – 2∆x because (yi+1 – yi) = 1 At this stage the basic algorithm is defined. We only need to calculate the initial value for parameter po. pi = 2⋅∆y⋅xi– 2⋅∆x⋅yi + 2⋅∆y + 2⋅∆x⋅b – ∆x from (7) p0 = 2⋅∆y⋅x0– 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅b – ∆x (9) For the initial point on the line: y0 = mx0 + b therefore b = y0 – (∆y/∆x) ⋅ x0 Substituting the above for b in (9)we get: p0 = 2⋅∆y⋅x0– 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅ [ y0 – (∆y/∆x) ⋅ x0 ] – ∆x = 2⋅∆y⋅x0 – 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅y0 – 2∆x⋅ (∆y/∆x) ⋅ x0 – ∆x simplify = 2⋅∆y⋅x0 – 2⋅∆x⋅y0 + 2⋅∆y + 2∆x⋅y0 – 2∆y⋅x0 – ∆x regroup = 2⋅∆y⋅x0 – 2∆y⋅x0 – 2⋅∆x⋅y0 + 2∆x⋅y0 + 2⋅∆y – ∆x simplify = 2⋅∆y – ∆x We can now write an outline of the complete algorithm. Algorithm 1. Input line endpoints, (X1,Y1) and (X2, Y2) 2. Calculate constants: ∆x = X2 – X1 ∆y = Y2 – Y1 2∆y 2∆y – ∆x 3. Assign value to the starting parameters: k = 0 p0 = 2∆y – ∆x 4. Plot the pixel at ((X1,Y1) 5. For each integer x-coordinate, xk, along the line if pk < 0 plot pixel at ( xk + 1, yk ) pk+1 = pk + 2∆y (note that 2∆y is a pre-computed constant) else plot pixel at ( xk + 1, yk + 1 ) pk+1 = pk + 2∆y – 2∆x (note that 2∆y – 2∆x is a pre-computed constant) increment k while xk < X2