COMPUTER GRAPHICS
PREPARED BY:
RUCHI MAURYA
BRESENHAM’S LINE
DRAWING ALGORITHM
INDEX
 INTRODUCTION
 DERIVATION
 EXAMPLE
 ADVANTAGES
 DISADVANTAGES
 REFERENCES
INTRODUCTION
• Raster line-generating algorithm
• Developed by Bresenham
• Scan conversion takes place
using only incremental integer
calculations
• Accurate and efficient than DDA
DERIVATION
• Starting from the left endpoint (x0, y0) of a given line,
we step to each successive column (x position) and plot
the pixel whose scan-line y value is closest to the line
path.
• At sample positions 𝑥 𝑘 + 1 the vertical separations
from the line are labelled 𝑑 𝑢𝑝𝑝𝑒𝑟 and 𝑑𝑙𝑜𝑤𝑒𝑟
• y coordinate on the line at 𝑥 𝑘 + 1 is,
𝑦 = 𝑚 𝑥 𝑘 + 1 + 𝑏
• so,
𝑑 𝑢𝑝𝑝𝑒𝑟 = 𝑦 − 𝑦 𝑘 = 𝑚 𝑥 𝑘 + 1 + 𝑏 − 𝑦 𝑘
𝑑𝑙𝑜𝑤𝑒𝑟 = 𝑦 𝑘 + 1 − 𝑦 = 𝑦 𝑘 + 1 − 𝑚 𝑥 𝑘 + 1 + 𝑏
𝑑𝑙𝑜𝑤𝑒𝑟
𝑑 𝑢𝑝𝑝𝑒𝑟
𝑥 𝑘 + 1
𝑦 𝑘 + 1
𝑦
𝑦 𝑘
DERIVATION
• It can be used to make decision about which pixel is closer to the line
• This decision is based on the difference between the two pixel positions,
𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟 = 2𝑚 𝑥 𝑘 + 1 − 2𝑦 𝑘 + 2𝑏 − 1
• By substituting 𝑚 = ∆𝑦/∆𝑥 and both are differences of end points,
∆𝑥 𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟 = ∆𝑥 2
∆𝑦
∆𝑥
𝑥 𝑘 + 1 − 2𝑦 𝑘 + 2𝑏 − 1
= 2∆𝑦. 𝑥 𝑘 − 2∆𝑥. 𝑦 𝑘 + 2∆𝑦 + ∆𝑥(2𝑏 − 1)
= 2∆𝑦. 𝑥 𝑘 − 2∆𝑥. 𝑦 𝑘 + 𝐶
DERIVATION
• Now, a decision parameter 𝑃𝑘 for the 𝑘th step along a line,
𝑃𝑘 = ∆𝑥 𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟
= 2∆𝑦. 𝑥 𝑘 − 2∆𝑥. 𝑦 𝑘 + 𝐶
• The sign of 𝑃𝑘 is same as that of 𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟
• If 𝑃𝑘 is –ve then we choose the lower pixel i.e. 𝑦 𝑘 only, otherwise we choose the upper
pixel i.e. 𝑦 𝑘 + 1
• So, for 𝑃𝑘 + 1 at step 𝑘 + 1,
𝑃𝑘+1 = 2∆𝑦. 𝑥 𝑘+1 − 2∆𝑥. 𝑦 𝑘+1 + 𝐶
• Subtracting 𝑃𝑘,
𝑃𝑘+1 − 𝑃𝑘 = 2∆𝑦(𝑥 𝑘+1 − 𝑥 𝑘) − 2∆𝑥(𝑦 𝑘+1 − 𝑦 𝑘) + 𝐶
DERIVATION
• 𝑥 𝑘+1 is same as 𝑥 𝑘 + 1 so,
𝑃𝑘+1 = 𝑃𝑘 + 2∆𝑦 − 2∆𝑥(𝑦 𝑘+1 − 𝑦 𝑘)
• Here, 𝑦 𝑘+1 − 𝑦 𝑘 is either 0 or 1 depending on the sign of 𝑃𝑘
• If 𝑃𝑘 < 0, the next point to plot is (𝑥 𝑘 + 1, 𝑦 𝑘) and new value of 𝑃 is,
𝑃𝑘+1 = 𝑃𝑘 + 2∆𝑦
• If 𝑃𝑘 > 0, the next point to plot is (𝑥 𝑘 + 1, 𝑦 𝑘 + 1) and new value of 𝑃 is,
𝑃𝑘+1 = 𝑃𝑘 + 2∆𝑦 − 2∆𝑥
• The first decision parameter 𝑃0 is evaluated at (𝑥0, 𝑦0) is,
𝑃0 = 2∆𝑦 − ∆𝑥
EXAMPLE
• End points (20,10) and (30,18)
• ∆𝑥=x2-x1 =30-20 =10
• ∆𝑦=y2-y1 =18-10 =8
• m= ∆𝑦/∆𝑥=8/10=0.8
𝑘 𝑃𝑘 (𝑥 𝑘+1, 𝑦 𝑘+1)
0 6 > 0 (21,11)
1 2 > 0 (22,12)
2 −2 < 0 (23,12)
3 14 > 0 (24,13)
4 10 > 0 (25,14)
𝑘 𝑃𝑘 (𝑥 𝑘+1, 𝑦 𝑘+1)
5 6 > 0 (26,15)
6 2 > 0 (27,16)
7 −2 < 0 (28,16)
8 14 > 0 (29,17)
9 10 > 0 (30,18)
EXAMPLE
21, 11
22, 12
23, 12
24, 13
25, 14 26, 15
27, 16
28, 16
29, 17
30, 18
10
11
12
13
14
15
16
17
18
19
20 21 22 23 24 25 26 27 28 29 30 31
ADVANTAGES
•Uses fixed points
•Easy to calculate (only addition & subtraction)
•Fast execution compare to DDA
•More accurate and efficient
DISADVANTAGES
• Drift away from actual line path
• Causes stair-case pattern
REFERENCES
•http://freefeast.info/
•http://www.expertsmind.com/
•http://www.answers.com/
THANKS A LOT….!!

Computer graphics - bresenham line drawing algorithm

  • 1.
  • 2.
  • 3.
    INDEX  INTRODUCTION  DERIVATION EXAMPLE  ADVANTAGES  DISADVANTAGES  REFERENCES
  • 4.
    INTRODUCTION • Raster line-generatingalgorithm • Developed by Bresenham • Scan conversion takes place using only incremental integer calculations • Accurate and efficient than DDA
  • 5.
    DERIVATION • Starting fromthe left endpoint (x0, y0) of a given line, we step to each successive column (x position) and plot the pixel whose scan-line y value is closest to the line path. • At sample positions 𝑥 𝑘 + 1 the vertical separations from the line are labelled 𝑑 𝑢𝑝𝑝𝑒𝑟 and 𝑑𝑙𝑜𝑤𝑒𝑟 • y coordinate on the line at 𝑥 𝑘 + 1 is, 𝑦 = 𝑚 𝑥 𝑘 + 1 + 𝑏 • so, 𝑑 𝑢𝑝𝑝𝑒𝑟 = 𝑦 − 𝑦 𝑘 = 𝑚 𝑥 𝑘 + 1 + 𝑏 − 𝑦 𝑘 𝑑𝑙𝑜𝑤𝑒𝑟 = 𝑦 𝑘 + 1 − 𝑦 = 𝑦 𝑘 + 1 − 𝑚 𝑥 𝑘 + 1 + 𝑏 𝑑𝑙𝑜𝑤𝑒𝑟 𝑑 𝑢𝑝𝑝𝑒𝑟 𝑥 𝑘 + 1 𝑦 𝑘 + 1 𝑦 𝑦 𝑘
  • 6.
    DERIVATION • It canbe used to make decision about which pixel is closer to the line • This decision is based on the difference between the two pixel positions, 𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟 = 2𝑚 𝑥 𝑘 + 1 − 2𝑦 𝑘 + 2𝑏 − 1 • By substituting 𝑚 = ∆𝑦/∆𝑥 and both are differences of end points, ∆𝑥 𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟 = ∆𝑥 2 ∆𝑦 ∆𝑥 𝑥 𝑘 + 1 − 2𝑦 𝑘 + 2𝑏 − 1 = 2∆𝑦. 𝑥 𝑘 − 2∆𝑥. 𝑦 𝑘 + 2∆𝑦 + ∆𝑥(2𝑏 − 1) = 2∆𝑦. 𝑥 𝑘 − 2∆𝑥. 𝑦 𝑘 + 𝐶
  • 7.
    DERIVATION • Now, adecision parameter 𝑃𝑘 for the 𝑘th step along a line, 𝑃𝑘 = ∆𝑥 𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟 = 2∆𝑦. 𝑥 𝑘 − 2∆𝑥. 𝑦 𝑘 + 𝐶 • The sign of 𝑃𝑘 is same as that of 𝑑 𝑢𝑝𝑝𝑒𝑟 − 𝑑𝑙𝑜𝑤𝑒𝑟 • If 𝑃𝑘 is –ve then we choose the lower pixel i.e. 𝑦 𝑘 only, otherwise we choose the upper pixel i.e. 𝑦 𝑘 + 1 • So, for 𝑃𝑘 + 1 at step 𝑘 + 1, 𝑃𝑘+1 = 2∆𝑦. 𝑥 𝑘+1 − 2∆𝑥. 𝑦 𝑘+1 + 𝐶 • Subtracting 𝑃𝑘, 𝑃𝑘+1 − 𝑃𝑘 = 2∆𝑦(𝑥 𝑘+1 − 𝑥 𝑘) − 2∆𝑥(𝑦 𝑘+1 − 𝑦 𝑘) + 𝐶
  • 8.
    DERIVATION • 𝑥 𝑘+1is same as 𝑥 𝑘 + 1 so, 𝑃𝑘+1 = 𝑃𝑘 + 2∆𝑦 − 2∆𝑥(𝑦 𝑘+1 − 𝑦 𝑘) • Here, 𝑦 𝑘+1 − 𝑦 𝑘 is either 0 or 1 depending on the sign of 𝑃𝑘 • If 𝑃𝑘 < 0, the next point to plot is (𝑥 𝑘 + 1, 𝑦 𝑘) and new value of 𝑃 is, 𝑃𝑘+1 = 𝑃𝑘 + 2∆𝑦 • If 𝑃𝑘 > 0, the next point to plot is (𝑥 𝑘 + 1, 𝑦 𝑘 + 1) and new value of 𝑃 is, 𝑃𝑘+1 = 𝑃𝑘 + 2∆𝑦 − 2∆𝑥 • The first decision parameter 𝑃0 is evaluated at (𝑥0, 𝑦0) is, 𝑃0 = 2∆𝑦 − ∆𝑥
  • 9.
    EXAMPLE • End points(20,10) and (30,18) • ∆𝑥=x2-x1 =30-20 =10 • ∆𝑦=y2-y1 =18-10 =8 • m= ∆𝑦/∆𝑥=8/10=0.8 𝑘 𝑃𝑘 (𝑥 𝑘+1, 𝑦 𝑘+1) 0 6 > 0 (21,11) 1 2 > 0 (22,12) 2 −2 < 0 (23,12) 3 14 > 0 (24,13) 4 10 > 0 (25,14) 𝑘 𝑃𝑘 (𝑥 𝑘+1, 𝑦 𝑘+1) 5 6 > 0 (26,15) 6 2 > 0 (27,16) 7 −2 < 0 (28,16) 8 14 > 0 (29,17) 9 10 > 0 (30,18)
  • 10.
    EXAMPLE 21, 11 22, 12 23,12 24, 13 25, 14 26, 15 27, 16 28, 16 29, 17 30, 18 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  • 11.
    ADVANTAGES •Uses fixed points •Easyto calculate (only addition & subtraction) •Fast execution compare to DDA •More accurate and efficient
  • 12.
    DISADVANTAGES • Drift awayfrom actual line path • Causes stair-case pattern
  • 13.
  • 14.