-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointOfLine.py
More file actions
74 lines (57 loc) · 1.43 KB
/
pointOfLine.py
File metadata and controls
74 lines (57 loc) · 1.43 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
import matplotlib.pyplot as plt
# variables declare:
print("Enter the value of x1 : ")
x1 = int(input())
print("Enter the value of y1 : ")
y1 = int(input())
print("Enter the value of xn : ")
xn = int(input())
print("Enter the value of yn : ")
yn = int(input())
# storing cordinates in list:
listX = [x1]
listY = [y1]
# Calculating value of delta-X and delta-Y:
deltaY = yn - y1
deltaX = xn - x1
# Calculate slop of line:
slope = deltaY / deltaX
# Decision Parameter P:
p = 2*deltaY - deltaX
# Initial point of a line:
print("(",x1,",",y1,") ")
# checking slope condition:
if slope < 1 :
while x1 < xn :
if p < 0 :
x1 = x1 + 1
y1 = y1
listX.append(x1)
listY.append(y1)
p = p + 2*deltaY
print("(",x1,",",y1,") ")
else :
x1 = x1 + 1
y1 = y1 + 1
listX.append(x1)
listY.append(y1)
p = p + 2*deltaY - 2*deltaX
print("(",x1,",",y1,") ")
else :
while x1 < xn :
if p < 0 :
x1 = x1
y1 = y1 + 1
listX.append(x1)
listY.append(y1)
p = p + 2*deltaX
print("(",x1,",",y1,") ")
else :
x1 = x1 + 1
y1 = y1 + 1
listX.append(x1)
listY.append(y1)
p = p + 2*deltaX - deltaY
print("(",x1,",",y1,") ")
plt.plot(listX,listY)
plt.show()