-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (59 loc) · 2.17 KB
/
main.py
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
from Giftwrapping import *
from Graham import *
from Divide_and_Conquer import *
from Quickhull import *
import random
import time
import matplotlib.pyplot as plt
import sys
def main(argv):
convex_hull = []
points = []
if len(argv)!=3:
print("Wrong Arguments!")
return -1
points_number = int(argv[1])
if(points_number<3):
print("Wrong Number of Points")
return -1
algorithm = argv[2]
while len(points) < points_number:
new_point = Point(random.randint(-50000, 50000), random.randint(-50000, 50000))
if new_point not in points: # Check if the point is not already in the list
points.append(new_point)
if algorithm == "Incremental":
start_time = time.time()
convex_hull = Graham_s_Scan(points)
end_time = time.time()
elif algorithm =="Gift":
start_time = time.time()
convex_hull= GiftWrapping(points)
end_time = time.time()
elif algorithm =="Divide":
start_time = time.time()
convex_hull = Divide_and_Conquer(points)
end_time = time.time()
elif algorithm =="Quickhull":
start_time = time.time()
convex_hull = Quickhull(points, 0)
end_time = time.time()
elif algorithm =="visual":
convex_hull = Quickhull(points, 1)
start_time =1
end_time = 1
print("-------------")
print("Convex Hull:")
print("-------------")
for i in range(len(convex_hull)):
convex_hull[i].print()
print("-------------")
elapsed_time = end_time - start_time
#print(elapsed_time)
print("Elapsed Time:", elapsed_time, "seconds")
plt.scatter([point.x for point in points], [point.y for point in points], color='blue', marker='o', label='Points')
plt.scatter([point.x for point in convex_hull], [point.y for point in convex_hull], color='red', marker='o', label='Points')
for i in range(len(convex_hull)):
plt.plot([convex_hull[i].x, convex_hull[(i+1) % len(convex_hull)].x], [convex_hull[i].y, convex_hull[(i+1) % len(convex_hull)].y], 'k-')
plt.show()
if __name__ == '__main__':
main(sys.argv)