ๅฐŠๆ•ฌ็š„ ๅพฎไฟกๆฑ‡็Ž‡๏ผš1ๅ†† โ‰ˆ 0.046166 ๅ…ƒ ๆ”ฏไป˜ๅฎๆฑ‡็Ž‡๏ผš1ๅ†† โ‰ˆ 0.046257ๅ…ƒ [้€€ๅ‡บ็™ปๅฝ•]
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

Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
Sneha Chopra
ย 
Cs580
Cs580Cs580
Cs580
Chellamuthu K
ย 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
Mazharul Islam
ย 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
Ketan Jani
ย 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
Yash Patel
ย 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
Mohd Arif
ย 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
Mani Kanth
ย 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
Kamal Acharya
ย 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
Taher Barodawala
ย 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
Ankit Garg
ย 
Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
Praveen Kumar
ย 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
Mohammad Sadiq
ย 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
aa11bb11
ย 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
shreeja asopa
ย 
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 algorithm
Ruchi Maurya
ย 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
Ankit Garg
ย 
BRESENHAMโ€™S LINE DRAWING ALGORITHM
BRESENHAMโ€™S  LINE DRAWING ALGORITHMBRESENHAMโ€™S  LINE DRAWING ALGORITHM
BRESENHAMโ€™S LINE DRAWING ALGORITHM
St Mary's College,Thrissur,Kerala
ย 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiion
MuhammadHamza401
ย 
Lect3cg2011
Lect3cg2011Lect3cg2011
Lect3cg2011
ishusharma6098
ย 

What's hot (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
ย 

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
ย 
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 Design
V Tripathi
ย 
Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1Tugas akhir matematika kelompok 1
Tugas akhir matematika kelompok 1
Debora Elluisa Manurung
ย 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
simpleok
ย 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
NaveenaKarthik3
ย 
Line circle draw
Line circle drawLine circle draw
Line circle draw
Praveen Kumar
ย 
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
ย 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
Mohd Arif
ย 
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
ย 
Mathematics 8 Linear Functions
Mathematics 8 Linear FunctionsMathematics 8 Linear Functions
Mathematics 8 Linear Functions
Juan Miguel Palero
ย 
Bresenhams
BresenhamsBresenhams
Bresenhams
Dharmendra Gupta
ย 
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
ย 

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
ย 
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
ย 
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
ย 
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
ย 

More from Kumar

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

More from 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
ย 

Recently uploaded

Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
ย 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
Quizzito The Quiz Society of Gargi College
ย 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
khabri85
ย 
Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
Ben Aldrich
ย 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
Celine George
ย 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
Kalna College
ย 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
ย 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
biruktesfaye27
ย 
bryophytes.pptx bsc botany honours second semester
bryophytes.pptx bsc botany honours  second semesterbryophytes.pptx bsc botany honours  second semester
bryophytes.pptx bsc botany honours second semester
Sarojini38
ย 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
MJDuyan
ย 
How to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRMHow to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRM
Celine George
ย 
Cross-Cultural Leadership and Communication
Cross-Cultural Leadership and CommunicationCross-Cultural Leadership and Communication
Cross-Cultural Leadership and Communication
MattVassar1
ย 
Creativity for Innovation and Speechmaking
Creativity for Innovation and SpeechmakingCreativity for Innovation and Speechmaking
Creativity for Innovation and Speechmaking
MattVassar1
ย 
managing Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptxmanaging Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptx
nabaegha
ย 
The Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teachingThe Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teaching
Derek Wenmoth
ย 
Decolonizing Universal Design for Learning
Decolonizing Universal Design for LearningDecolonizing Universal Design for Learning
Decolonizing Universal Design for Learning
Frederic Fovet
ย 
Erasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES CroatiaErasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES Croatia
whatchangedhowreflec
ย 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
PJ Caposey
ย 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
ย 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Catherine Dela Cruz
ย 

Recently uploaded (20)

Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
ย 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
ย 
Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024Brand Guideline of Bashundhara A4 Paper - 2024
Brand Guideline of Bashundhara A4 Paper - 2024
ย 
Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
ย 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
ย 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
ย 
Observational Learning
Observational Learning Observational Learning
Observational Learning
ย 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
ย 
bryophytes.pptx bsc botany honours second semester
bryophytes.pptx bsc botany honours  second semesterbryophytes.pptx bsc botany honours  second semester
bryophytes.pptx bsc botany honours second semester
ย 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
ย 
How to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRMHow to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRM
ย 
Cross-Cultural Leadership and Communication
Cross-Cultural Leadership and CommunicationCross-Cultural Leadership and Communication
Cross-Cultural Leadership and Communication
ย 
Creativity for Innovation and Speechmaking
Creativity for Innovation and SpeechmakingCreativity for Innovation and Speechmaking
Creativity for Innovation and Speechmaking
ย 
managing Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptxmanaging Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptx
ย 
The Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teachingThe Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teaching
ย 
Decolonizing Universal Design for Learning
Decolonizing Universal Design for LearningDecolonizing Universal Design for Learning
Decolonizing Universal Design for Learning
ย 
Erasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES CroatiaErasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES Croatia
ย 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
ย 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
ย 
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptxScience-9-Lesson-1-The Bohr Model-NLC.pptx pptx
Science-9-Lesson-1-The Bohr Model-NLC.pptx pptx
ย 

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
  ็ฟป่ฏ‘๏ผš