-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBLDA.py
More file actions
80 lines (61 loc) · 2.03 KB
/
Copy pathBLDA.py
File metadata and controls
80 lines (61 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import matplotlib.pyplot as plt
print("Bresenham Line Drawing Algo")
global x1, y1, x2, y2
x1 = int(input("Enter Xo : "))
y1 = int(input("Enter Yo : "))
x2 = int(input("Enter Xn : "))
y2 = int(input("Enter Yn : "))
x_coordinate = []
y_coordinate = []
def show(x1, y1, x2, y2):
print(" ")
print("X0 : ", x1, " ", "Y0 : ", y1)
print("Xn : ", x2, " ", "Yn : ", y2)
def delta(x1, y1, x2, y2):
global delta_x, delta_y
delta_x = x2 - x1
delta_y = y2 - y1
print(" ")
print("Delta X : ", delta_x)
print("Delta Y : ", delta_y)
print(" ")
def pk(delta_x, delta_y, x1, y1):
pk = 2 * delta_y - delta_x
print("|", "i", "|" + "PK" + " | " + "PK + 1" + " | " + "X1" + " | " + "Y1" + " | " + " Plot")
for i in range(0, delta_x):
if (pk > 0):
pk_1 = pk + (2 * delta_y - 2 * delta_x)
print("|", i, "|", pk, "| ", pk_1, " |", x1, " |", y1, " |", "(", x1, ",", y1, ")")
x1 += 1
y1 += 1
x_coordinate.append(x1)
y_coordinate.append(y1)
pk = pk_1
else:
pk_1 = pk + 2 * delta_y
print("|", i, "|", pk, "| ", pk_1, " |", x1, " |", y1, "|", "(", x1, ",", y1, ")")
x1 += 1
pk = pk_1
x_coordinate.append(x1)
y_coordinate.append(y1)
print(" ")
print("X Points : ", x_coordinate)
print("Y Points : ", y_coordinate)
starting_coordinate = []
ending_coordinate = []
x_coordinates = (x_coordinate[0], x_coordinate[-1])
y_coordinates = (y_coordinate[0], y_coordinate[-1])
print(" ")
print("Starting Coordinate : ", x_coordinates)
print("Ending Coordinate : ", y_coordinates)
plt.scatter(x_coordinate, y_coordinate, color='blue', s=20)
plt.plot(x_coordinates, y_coordinates, 'r', linewidth="1")
plt.xlabel('X Co-ordinates')
plt.ylabel("Y Co-ordinate")
plt.xlim(0, 35)
plt.ylim(0, 20)
plt.grid(True)
plt.show()
show(x1, y1, x2, y2)
delta(x1, y1, x2, y2)
pk(delta_x, delta_y, x1, y1)