CG 03 Line Plotting 2
CG 03 Line Plotting 2
Assuming that:
–East?
–Northeast? E
Midpoint Algorithm
Which pixel should
be plotted next?
– East?
f <0
– Northeast?
Line equation
NE
y = mx + b
f(x,y) = mx + b – y f>0
M
E
Midpoint Algorithm
Which pixel should be
plotted next?
– East?
– Northeast? f <0
Line equation
NE
y = mx +b
f >0
M
E
y = mx + B.
E
Calculation For initial value of decision parameter d0:
d0 = F(X1+1 , Y1+1/2)
= F(X1,Y1) + a + b/2
If E chosen :
1 1
d new = F ( x p + 2, y p + ) = a( x p + 2) + b( y p + ) + c
2 2
But recall :
NE
E So :
Previous Choices for
Pixel Choices for Next pixel d new = d old + dy
(xp,yp) Current pixel
Case 1: If E is chosen then for next point :
dnew = F(Xp+2, Yp+1/2)
= a(Xp+2) + b(Yp+1/2) + c
dold = a(Xp+1) + b(Yp+1/2) + c
Difference (Or delta) of two distances:
DELd = dnew – dold
= a(Xp+2)- a(Xp+1)+ b(Yp+1/2)- b(Yp+1/2)+ c-c
= a(Xp) +2a – a(Xp) – a
= a.
Therefore, dnew = dold + dy. (as a = dy)
Decision variable.
If NE was chosen :
3 3
d new = F ( x p + 2, y p + ) = a( x p + 2) + b( y p + ) + c
2 2
M So :
NE
d new = d old + dy − dx
E
Previous Choices for
Pixel Choices for Next pixel
(xp,yp) Current pixel
Case 2: If NE is chosen then for next point :
= a(Xp+2) + b(Yp+3/2) + c
=a+b
d new = d old + dy − dx
Line drawing Exercise
d new = d old + dy − dx