-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_analysis.py
68 lines (55 loc) · 1.51 KB
/
list_analysis.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
# from main import jarvis
import random
import time
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def jarvis(points):
n = len(points)
if n == 0:
return points
convex_set = []
l = 0
i = 1
while i < n:
if points[i].x < points[l].x:
l = i
i += 1
p = l
q = (p + 1) % n
while True:
j = (q + 1) % n
found = True
c_a = points[q].x - points[p].x
d_b = points[q].y - points[p].y
while j != q:
e_a = points[j].x - points[p].x
f_b = points[j].y - points[p].y
det = f_b * c_a - d_b * e_a # determinant
# we'll take advantage of the fact that the determinant gives us the orientation as well
if det > 0: # if there is a point j which is left to line p-q
found = False
j = (j + 1) % n
if found:
convex_set.append(points[q])
p = q
if p == l: # came back to the starting point i.e. loop is complete
break
q = (q + 1) % n
return convex_set
def generate_random_points(size):
points = []
for _ in range(size):
x = random.randint(0, 100)
y = random.randint(0, 100)
points.append(Point(x, y))
return points
times = []
for i in range(350, 360, 10):
points = generate_random_points(i)
t1 = time.time()
jarvis(points)
t2 = time.time()
times.append(t2-t1)
print(times)