NOTES
Here covering topics are: 1. Straight line equation, 2. DDA, 3. Bresenham line
Equation of a straight line -
DDA Algorithm (Digital Differential Analyzer)-
∆y = 1) and calculate xk+1 = xk + 1/m .
Program:
from graphics import *
import time
def PutPixle(win, x, y):
pt = Point(x,y)
pt.draw(win)
print(x,y)
win = GraphWin('DDA Line', 600, 600)
x=int(input("Enter the initial position of X: "))
y=int(input("Enter the initial position of Y: "))
x1=int(input("Enter the final position of X: "))
y1=int(input("Enter the final position of Y: "))
dely = y1-y
delx=x1-x
slope=dely/delx
if slope>1.0:
while y<y1:
PutPixle(win, x, y)
x=x+(1/slope)
y=y+1.0
else:
while x<=x1:
PutPixle(win, x, y)
y=y+slope
x=x+1.0
win.getMouse()
Output is generated appropriately.
********************************************************
BRESENHAM LINE DRAWING ALGORITHM
An accurate and efficient line generating algorithm developed by Bresenham. It uses incremental interger calculation that can be adopted to draw circle and curves as well.
We first consider the scan conversion process for lines with positive slope less than 1 (m<1).
The pixel positions along a line path are determine by sampling at unit x interval (∆x = 1), plot pixel whose y value is closest to the line path.
Assuming, We have determine that pixel at (xk, yk) is to be displayed, we next need to decide which pixel to plot in column xk+1. Our choices are (xk+1, yk) or (xk+1, yk+1).
y= m(xk +1)+b