Professional Documents
Culture Documents
– (51,50) or (51,49) ?
– Answered by Bresenham
Fig. 3.18 Section of a display screen where
a negative slope line segment is to be
plotted, starting from the pixel at column
50 on scan line 50.
3
Bresenham’s Line Drawing Algorithm
continued..
For |m|<1
– Start from left end point (x0,y0) step to each
successive column (x samples) and plot the pixel
whose scan line y value is closest to the line path.
– After (xk,yk) the choice could be (xk+1,yk) or
(xk+1,yk+1)
4
Bresenham’s Line Drawing Algorithm
contd.
y m(x k 1) b
d1 y y k
m(x k 1) b yk
d 2 ( yk 1) y
yk 1 m(x k 1) b
Difference between separations
Fig. 3.19 Distances between pixel
positions and the line y coordinate at
d1 d 2 2m(x k 1) 2 yk 2b 1 sampling position xk+ I. [1]
5
Bresenham’s Line Drawing Algorithm
contd.
y mx c
y k m( x k 1) c Equation 1
d1 y y k
m( x k 1) c y k Equation 2
d 2 ( y k 1) y k
d 2 ( y k 1) [ m( x k 1) c ]
d1 d 2 [ m( x k 1) c y k ] [( y k 1) [ m( x k 1) c ]]
d1 d 2 m( x k 1) c y k ( y k 1) [ m( x k 1) c ]
d1 d 2 m( x k 1) c y k y k 1 m( x k 1) c
d1 d 2 2m( x k 1) 2 y k 2c 1 Equation 3
6
Bresenham’s Line Drawing Algorithm
contd.
y
now multiply both sides by x and put the value of m in equation 3
x
x( d1 d 2 ) x[ 2m( x k 1) 2 y k 2c 1]
y
x( d1 d 2 ) x[ 2 ( x 1) 2 y 2c 1]
x k k
y
x( d1 d 2 ) x 2 ( x k 1) 2xy k x( 2c 1)
x
y
Pk x( d1 d 2 ) x . 2 ( x k 1) 2x . y k x( 2c 1)
x
Pk 2y . x k 2y 2x . y k x( 2c 1)
Pk 2y . x 2x . y 2y 2cx x
k k
Pk 2y . x k 2x . y k C where C 2y 2cx x
7
Bresenham’s Line Drawing
Algorithm contd.
Pk 2y . x k 2x . y k C Equation 4
Pk 1 2y . x k 1 2x . y k 1 C Equation 5
Pk 1 Pk [2y . x k 1 2x . y k 1 C ] [2y . x k 2x . y k C ]
8
Bresenham’s Line Drawing
Algorithm contd.
But x x 1 , Now put this value in equation 6 we have
k 1 k
Pk 1 Pk 2y . ( x 1 x ) 2x . ( y y )
k k k 1 k
Pk 1 Pk 2y 2x . ( y y )
k 1 k
Pk 1 Pk 2y 2x . ( y k 1 y k ) Equation 7
pk x(d1 d 2 ) [1]
2y.xk 2x.yk c
Sign of pk is same as that of d1-d2 for Δx>0 (left to right sampling)
pk 1 2y.xk 1 2x.yk 1 c c eliminated here
pk 1 pk
2y(x k 1 xk ) 2x( yk 1 because xk+1 = xk + 1
yk )
p p
2y 2x( yk 1 yk+1-yk = 0 if pk < 0 & yk+1-yk = 1 if pk ≥ 0
For Recursive calculation,
k 1 k
yk ) initially
13
Example For Bresenham’s Line
Drawing
Endpoints (20,10) and (30,18)
Slope m = 0.8 Δx = 10, Δy = 8
P0 = 2Δy - Δx = 6
2Δy = 16, 2Δy-2Δx = -4
Plot (x0,y0) = (20,10)
Fig. 3.20 A plot of the pixels generated along this line path [1]
14
Another Example For Bresenham’s
Line Drawing
Digitize a line with endpoints
19
(15,18) and (10,15) using BLA.
Table 3.8 Pixel calculation of line with 18
endpoints (15, 18) and (10, 15)
K Pk Xk+1 Yk+1 17
0 1 11 16
16
1 -3 12 16
15
2 3 13 17
3 -1 14 17 10 11 12 13 14 15
15
Another example For Bresenham’s
Line Drawing
Digitize a line with endpoints
19
(15,15) and (10,18) using
BLA.
Table 3.9 - Pixel calculation of line with 18
endpoints (15, 15) and (10, 18)
K Pk Xk+1 Yk+1 17
0 1 11 17 16
1 -3 12 17
15
2 3 13 16
3 -1 14 16 10 11 12 13 14 15 16
17
References
1. Computer Graphics, 2nd Ed., Hearn & Baker –PHI, New Delhi.
18
THANK YOU
19