Beruflich Dokumente
Kultur Dokumente
Yi Xi Xi+1
D=d1-d2
Yi
d2 d1
<0 >0
Decision Parameter
Xi
Xi+1
8/12/2009
d2 d1
y = m(x+1) + b
Yi+1 Yi Xi Xi+1
d2 d1
y = mx + b
D= m(Xi+1)+b-Yi D=2m(Xi+1)-2Yi+2b-1
D=d1-d2
Xi Xi+1
8/12/2009
D= m(Xi+1)+b-Yi D=2m(Xi+1)-2Yi+2b-1
Floating point calculation
10
11
12
8/12/2009
Now if Pi <0 Lower pixel is chosen i.e. (xi+1,yi) xi+1=xi+1 & yi+1=yi substituting it in 2 we get
Pi+1 =Pi+ 2 3
Now if Pi >0 upper pixel is chosen i.e. (xi+1,yi +1) xi+1=xi+1 & yi+1=yi +1 substituting it in 2 we get
Pi+1 =Pi+ 2( yx) 4
13
14
ALGORITHM
1. 2. 3. Input the two end points and store left pt in (x0,y0) Calculate y, x, 2 y and 2( y- x) and calculate P0 P0=2 y- x At each Xi along the line, starting at i=0 perform the following test If (Pi<0) the next point plotted would be(Xi+1,Yi) Pi+1=Pi+2 y Otherwise the next point would be (Xi+1,Yi+1) and Pi+1=P + 2( y- x) Repeat step 3 x times
Nihar Ranjan Roy
15
16
8/12/2009
PROBLEM
Raster plot all the points that make the line with end points (20,10) and (26,15) using Bresenhams Line drawing algorithm
(20,10)
Nihar Ranjan Roy
17
18
y=5 2 y=10
(Xi+1,Yi+1) (21,11)
2( y- x)=-2
y=5 2 y=10
(Xi+1,Yi+1) (21,11) (22,12)
2( y- x)=-2
Pi P0=4
(26,15)
19
20
8/12/2009
y=5 2 y=10
(Xi+1,Yi+1) (21,11) (22,12) (23,13)
2( y- x)=-2
y=5 2 y=10
(Xi+1,Yi+1) (21,11) (22,12) (23,13) (24,13)
2( y- x)=-2
(22,12) (23,13)
(26,15)
21
22
y=5 2 y=10
(Xi+1,Yi+1) (21,11) (22,12) (23,13) (24,13) (25,14)
2( y- x)=-2
Pi P0=4 P1=2 P2=0 P3 =-2 P4=8 P5=6 (Xi+1,Yi+1) (21,11) (22,12) (23,13) (24,13) (25,14) (26,15)
y=5 2 y=10
2( y- x)=-2
(26,15)
23
24
8/12/2009
y=5 2 y=10
(Xi+1,Yi+1) (21,11) (22,12) (23,13) (24,13) (25,14) (26,15)
2( y- x)=-2
25