Docsity

Bresenham's Line Algorithm: A Raster Graphics Drawing Technique, Lecture notes of Computer Science

Partial preview of the text

Download Bresenham's Line Algorithm: A Raster Graphics Drawing Technique and more Lecture notes Computer Science in PDF only on Docsity!

COMPUTER GRAPHICS

PREPARED BY:

RUCHI MAURYA

BRESENHAMโ€™S LINE DRAWING ALGORITHM

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

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

REFERENCES

  • http://freefeast.info/
  • http://www.expertsmind.com/
  • http://www.answers.com/

THANKS A LOTโ€ฆ.!!