Mid Point Line Drawing Algorithm:
import [Link] as plt
[Link]("Midpoint Line Algorithm")
[Link]("X Axis")
[Link]("Y Axis")
def midpoint(x1, y1, x2, y2):
dx = x2 - x1
dy = y2 - y1
# Initialize the decision parameter
d = dy - (dx/2)
x = x1
y = y1
print(f"x = {x}, y = {y}")
# Initialize the plotting points
xcoordinates = [x]
ycoordinates = [y]
while (x<x2):
x=x+1
# East is Chosen
if (d<0):
d = d + dy
# North East is Chosen
else:
d = d + (dy - dx)
y=y+1
[Link](x)
[Link](y)
print(f"x = {x}, y = {y}")
[Link](xcoordinates, ycoordinates)
[Link]()
if __name__=="__main__":
x1 = int(input("Enter the starting point of x: "))
y1 = int(input("Enter the starting point of y: "))
x2 = int(input("Enter the end point of x: "))
y2 = int(input("Enter the end point of y: "))
midpoint(x1, y1, x2, y2)
Output: