SlideShare a Scribd company logo
1 of 22
Line Drawing Algorithms
1. A line in Computer graphics is a portion of
straight line that extends indefinitely in opposite
direction.
2. It is defined by its two end points.
3. Its density should be independent of line length.
the slope intercept equation for a line:
y = mx + b (1)
where, m = Slope of the line
b = the y intercept of a line
The two endpoints of a line segment are specified at
positions (x1,y1) and (x2,y2).
x
y
P1(x1,y1)
P2(x2,y2)
b
0
We can determine the value for slope m & b intercept
as
m = y2-y1/x2-x1
i.e. m= Δy/ Δx (2)
Example 1 The endpoints of line are(0,0) & (6,18).
Compute each value of y as x steps from 0 to 6 and
plot the result.
Solution : Equation of line is y= mx +b
m = y2-y1/x2-x1= 18-0/6-0 = 3
Next the y intercept b is found by plugging y1& x1 into
the equation y = 3x + b,
0 = 3(0) + b. Therefore, b=0, so the equation for the
line is y= 3x.
The challenge is to find a way to calculate the next x,y
position by previous one as quickly as possible.
DDA Algorithm
The Digital differential analyzer (DDA)
algorithm is an incremental scan-conversion
method.
Such an approach is characterized by
performing calculations at each step using results
from the preceding step.
Algorithm:
(x1,y1) (x2,y2) are the end points and dx, dy are
the float variables.
Where dx= abs(x2-x1) and dy= abs(y2-y1)
(i) If dx >=dy then
length = dx
else
length = dy
endif
(ii) dx = (x2-x1)/length
dy = (y2-y1)/length
(iii) x = x1 + 0.5
y = y1 + 0.5
(iv) i = 0
(v) Plot ((x), (y))
(vi) x = x + dx
y = y + dy
(vii) i = i + 1
(viii) If i < length then go to step (v)
(ix) Stop
Example 2 Scan convert a line having end points
(3,2) & (4,7) using DDA.
Solution: dx= x2 - x1 = 4-3 = 1
dy= y2 - y1 = 7-2 = 5
As, dx < dy then
length = y2-y1 = 5
dx = (x2-x1)/ length = 1/5 =0.2
dy = (y2-y1)/ length = 5/5 = 1
x1 y1 x2 y2 m dx dy i x y Result Plot
3 2 4 7 5 .2 1 0 3.5 2.5 3.5, 2.5 3,2
1 3.7 3.5 3.7,3.5 3,3
2 3.9 4.5 3.9,4.5 3,4
3 4.1 5.5 4.1,5.5 4,5
4 4.3 6.5 4.3,6.5 4,6
5 4.5 7.5 4.5,7.5 4,7
Limitations of DDA:
(1) The rounding operation & floating point
arithmetic are time consuming procedures.
(2) Round-off error can cause the calculated pixel
position to drift away from the true line path for
long line segment.
The Bresenham Line Algorithm
The Bresenham algorithm is another incremental scan
conversion algorithm
The big advantage of this algorithm is that it uses only
integer calculations
Move across the x axis in unit intervals and at each step
choose between two different y coordinates
2 3 4 5
2
4
3
5
For example, from
position (2, 3) we have
to choose between (3,
3) and (3, 4)
We would like the
point that is closer to
the original line
(xk, yk)
(xk+1, yk)
(xk+1, yk+1)
The y coordinate on the mathematical line at xk+1
is:
Deriving The Bresenham Line Algorithm
At sample position xk+1 the
vertical separations from the
mathematical line are
labelled dupper and dlower
b
x
m
y k 

 )
1
(
y
yk
yk+1
xk+1
dlower
dupper
The Bresenham Line Algorithm
BRESENHAM’S LINE DRAWING ALGORITHM
1. Input the two line end-points, storing the left end-point in (x1,
y1)
2. Calculate the constants Δx i.e. dx, Δy i.e. dy, 2Δy and 2 Δx,
get the first value for the decision parameter as:
3. Initialise starting
4. If e< 0 , then the next point to plot is (xk+1, yk+1) and:
y
e
e 

 2
x
y
e 


 2
e
The Bresenham Line Algorithm (cont…)
The algorithm and derivation above assumes slopes are
less than 1. for other slopes we need to adjust the
algorithm slightly.
Otherwise, the next point to plot is (xk+1, yk+1) and:
5. Repeat step 4 (Δx – 1) times
x
y
p
p k
k 




 2
2
1
Adjustment
For m>1, we will find whether we will increment x while
incrementing y each time.
After solving, the equation for decision parameter pk will
be very similar, just the x and y in the equation will get
interchanged.
Bresenham Example
Let’s have a go at this
Let’s plot the line from (20, 10) to (30, 18)
First off calculate all of the constants:
 Δx: 10
 Δy: 8
 2Δy: 16
 2Δy - 2Δx: -4
Calculate the initial decision parameter p0:
 p0 = 2Δy – Δx = 6
Bresenham Example (cont…)
17
16
15
14
13
12
11
10
18
29
27
26
25
24
23
22
21
20 28 30
k pk (xk+1,yk+1)
0
1
2
3
4
5
6
7
8
9
Bresenham Exercise
Go through the steps of the Bresenham line drawing
algorithm for a line going from (21,12) to (29,16)
Bresenham Exercise (cont…)
17
16
15
14
13
12
11
10
18
29
27
26
25
24
23
22
21
20 28 30
k pk (xk+1,yk+1)
0
1
2
3
4
5
6
7
8
Bresenham Line Algorithm Summary
The Bresenham line algorithm has the following
advantages:
 An fast incremental algorithm
 Uses only integer calculations
Comparing this to the DDA algorithm, DDA has the
following problems:
 Accumulation of round-off errors can make the
pixelated line drift away from what was intended
 The rounding operations and floating point arithmetic
involved are time consuming

More Related Content

Similar to Computer graphics LINE DRAWING algorithm.pptx

OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxAlamelu
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationMuhammad Fiaz
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithmnehrurevathy
 
Applications of Differential Calculus in real life
Applications of Differential Calculus in real life Applications of Differential Calculus in real life
Applications of Differential Calculus in real life OlooPundit
 
C2 st lecture 4 handout
C2 st lecture 4 handoutC2 st lecture 4 handout
C2 st lecture 4 handoutfatima d
 
Lect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsLect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsBCET
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptxAhmadAbba6
 
Bahan ajar kalkulus integral
Bahan ajar kalkulus integralBahan ajar kalkulus integral
Bahan ajar kalkulus integralgrand_livina_good
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptKhondokarMdMehediHas
 
Advanced Engineering Mathematics Solutions Manual.pdf
Advanced Engineering Mathematics Solutions Manual.pdfAdvanced Engineering Mathematics Solutions Manual.pdf
Advanced Engineering Mathematics Solutions Manual.pdfWhitney Anderson
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptxssuser255bf1
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 

Similar to Computer graphics LINE DRAWING algorithm.pptx (20)

OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Applications of Differential Calculus in real life
Applications of Differential Calculus in real life Applications of Differential Calculus in real life
Applications of Differential Calculus in real life
 
C2 st lecture 4 handout
C2 st lecture 4 handoutC2 st lecture 4 handout
C2 st lecture 4 handout
 
Calculus Assignment Help
Calculus Assignment HelpCalculus Assignment Help
Calculus Assignment Help
 
Calculus Homework Help
Calculus Homework HelpCalculus Homework Help
Calculus Homework Help
 
Lect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygonsLect3 bresenham circlesandpolygons
Lect3 bresenham circlesandpolygons
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
 
Bahan ajar kalkulus integral
Bahan ajar kalkulus integralBahan ajar kalkulus integral
Bahan ajar kalkulus integral
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Aieee Maths 2004
Aieee Maths  2004Aieee Maths  2004
Aieee Maths 2004
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
 
Advanced Engineering Mathematics Solutions Manual.pdf
Advanced Engineering Mathematics Solutions Manual.pdfAdvanced Engineering Mathematics Solutions Manual.pdf
Advanced Engineering Mathematics Solutions Manual.pdf
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Nis differentiation1
Nis differentiation1Nis differentiation1
Nis differentiation1
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Computer graphics LINE DRAWING algorithm.pptx

  • 1. Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined by its two end points. 3. Its density should be independent of line length. the slope intercept equation for a line: y = mx + b (1) where, m = Slope of the line b = the y intercept of a line
  • 2. The two endpoints of a line segment are specified at positions (x1,y1) and (x2,y2). x y P1(x1,y1) P2(x2,y2) b 0
  • 3. We can determine the value for slope m & b intercept as m = y2-y1/x2-x1 i.e. m= Δy/ Δx (2)
  • 4. Example 1 The endpoints of line are(0,0) & (6,18). Compute each value of y as x steps from 0 to 6 and plot the result. Solution : Equation of line is y= mx +b m = y2-y1/x2-x1= 18-0/6-0 = 3 Next the y intercept b is found by plugging y1& x1 into the equation y = 3x + b, 0 = 3(0) + b. Therefore, b=0, so the equation for the line is y= 3x.
  • 5. The challenge is to find a way to calculate the next x,y position by previous one as quickly as possible.
  • 6. DDA Algorithm The Digital differential analyzer (DDA) algorithm is an incremental scan-conversion method. Such an approach is characterized by performing calculations at each step using results from the preceding step.
  • 7. Algorithm: (x1,y1) (x2,y2) are the end points and dx, dy are the float variables. Where dx= abs(x2-x1) and dy= abs(y2-y1) (i) If dx >=dy then length = dx else length = dy endif
  • 8. (ii) dx = (x2-x1)/length dy = (y2-y1)/length (iii) x = x1 + 0.5 y = y1 + 0.5 (iv) i = 0 (v) Plot ((x), (y)) (vi) x = x + dx y = y + dy (vii) i = i + 1
  • 9. (viii) If i < length then go to step (v) (ix) Stop Example 2 Scan convert a line having end points (3,2) & (4,7) using DDA. Solution: dx= x2 - x1 = 4-3 = 1 dy= y2 - y1 = 7-2 = 5 As, dx < dy then length = y2-y1 = 5 dx = (x2-x1)/ length = 1/5 =0.2 dy = (y2-y1)/ length = 5/5 = 1
  • 10. x1 y1 x2 y2 m dx dy i x y Result Plot 3 2 4 7 5 .2 1 0 3.5 2.5 3.5, 2.5 3,2 1 3.7 3.5 3.7,3.5 3,3 2 3.9 4.5 3.9,4.5 3,4 3 4.1 5.5 4.1,5.5 4,5 4 4.3 6.5 4.3,6.5 4,6 5 4.5 7.5 4.5,7.5 4,7
  • 11. Limitations of DDA: (1) The rounding operation & floating point arithmetic are time consuming procedures. (2) Round-off error can cause the calculated pixel position to drift away from the true line path for long line segment.
  • 12. The Bresenham Line Algorithm The Bresenham algorithm is another incremental scan conversion algorithm The big advantage of this algorithm is that it uses only integer calculations
  • 13. Move across the x axis in unit intervals and at each step choose between two different y coordinates 2 3 4 5 2 4 3 5 For example, from position (2, 3) we have to choose between (3, 3) and (3, 4) We would like the point that is closer to the original line (xk, yk) (xk+1, yk) (xk+1, yk+1)
  • 14. The y coordinate on the mathematical line at xk+1 is: Deriving The Bresenham Line Algorithm At sample position xk+1 the vertical separations from the mathematical line are labelled dupper and dlower b x m y k    ) 1 ( y yk yk+1 xk+1 dlower dupper
  • 15. The Bresenham Line Algorithm BRESENHAM’S LINE DRAWING ALGORITHM 1. Input the two line end-points, storing the left end-point in (x1, y1) 2. Calculate the constants Δx i.e. dx, Δy i.e. dy, 2Δy and 2 Δx, get the first value for the decision parameter as: 3. Initialise starting 4. If e< 0 , then the next point to plot is (xk+1, yk+1) and: y e e    2 x y e     2 e
  • 16. The Bresenham Line Algorithm (cont…) The algorithm and derivation above assumes slopes are less than 1. for other slopes we need to adjust the algorithm slightly. Otherwise, the next point to plot is (xk+1, yk+1) and: 5. Repeat step 4 (Δx – 1) times x y p p k k       2 2 1
  • 17. Adjustment For m>1, we will find whether we will increment x while incrementing y each time. After solving, the equation for decision parameter pk will be very similar, just the x and y in the equation will get interchanged.
  • 18. Bresenham Example Let’s have a go at this Let’s plot the line from (20, 10) to (30, 18) First off calculate all of the constants:  Δx: 10  Δy: 8  2Δy: 16  2Δy - 2Δx: -4 Calculate the initial decision parameter p0:  p0 = 2Δy – Δx = 6
  • 20. Bresenham Exercise Go through the steps of the Bresenham line drawing algorithm for a line going from (21,12) to (29,16)
  • 22. Bresenham Line Algorithm Summary The Bresenham line algorithm has the following advantages:  An fast incremental algorithm  Uses only integer calculations Comparing this to the DDA algorithm, DDA has the following problems:  Accumulation of round-off errors can make the pixelated line drift away from what was intended  The rounding operations and floating point arithmetic involved are time consuming