-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGiftwrapping.py
More file actions
35 lines (24 loc) · 744 Bytes
/
Giftwrapping.py
File metadata and controls
35 lines (24 loc) · 744 Bytes
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
from points import *
def GiftWrapping(points):
vertexes = []
# select the leftmost point
r0 = min(points, key = lambda k:[k.x, k.y])
# add r0 to convex hull
vertexes.append(r0)
while True:
# r is the last vertex to be added
r = vertexes[-1]
# to make sure the algorithm works always pick the first out of points for u
u = points[0]
for t in points:
if(u.same(t)==True):
continue
if(orientation(r,u,t)==2):
u = t
if(u.same(r0)==True):
break
else:
r = u
points.remove(r)
vertexes.append(r)
return vertexes