SlideShare uma empresa Scribd logo
1 de 3
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivationMazharul Islam
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
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
 
Computer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmComputer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmRuchi Maurya
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithmAnkit Garg
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiionMuhammadHamza401
 

Mais procurados (20)

Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Cs580
Cs580Cs580
Cs580
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
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...
 
Computer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithmComputer graphics - bresenham line drawing algorithm
Computer graphics - bresenham line drawing algorithm
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
 
BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiion
 
Lect3cg2011
Lect3cg2011Lect3cg2011
Lect3cg2011
 

Semelhante a Bresenham derivation

Computer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxComputer graphics LINE DRAWING algorithm.pptx
Computer graphics LINE DRAWING algorithm.pptxR S Anu Prabha
 
Bresenham's line algo.
Bresenham's line algo.Bresenham's line algo.
Bresenham's line algo.Mohd Arif
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing DesignV Tripathi
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenhamsimpleok
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
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-phpapp01Nur Kamila
 
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-phpapp01Asad Bukhari
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
C2 st lecture 6 handout
C2 st lecture 6 handoutC2 st lecture 6 handout
C2 st lecture 6 handoutfatima d
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 
Mathematics 8 Linear Functions
Mathematics 8 Linear FunctionsMathematics 8 Linear Functions
Mathematics 8 Linear FunctionsJuan Miguel Palero
 
Module 1 linear functions
Module 1   linear functionsModule 1   linear functions
Module 1 linear functionsdionesioable
 
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 odjoqwddoioNoorYassinHJamel
 

Semelhante a 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
 
Bresenham's line algo.
Bresenham's line algo.Bresenham's line algo.
Bresenham's line algo.
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
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
 
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
 
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
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
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
 
Mathematics 8 Linear Functions
Mathematics 8 Linear FunctionsMathematics 8 Linear Functions
Mathematics 8 Linear Functions
 
Bresenhams
BresenhamsBresenhams
Bresenhams
 
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
 

Mais de Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devicesKumar
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithmsKumar
 
region-filling
region-fillingregion-filling
region-fillingKumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xsltKumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xmlKumar
 
Xml basics
Xml basicsXml basics
Xml basicsKumar
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xmlKumar
 
Applying xml
Applying xmlApplying xml
Applying xmlKumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLKumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB FundmentalsKumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programmingKumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EEKumar
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)Kumar
 
Android structure
Android structureAndroid structure
Android structureKumar
 

Mais de Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
region-filling
region-fillingregion-filling
region-filling
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)
 
Android structure
Android structureAndroid structure
Android structure
 

Último

Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 

Último (20)

Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 

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