This commit is contained in:
Casper 2018-09-20 16:54:47 +02:00
parent 1bbb5d9cf3
commit 55bf40ddf6
1 changed files with 14 additions and 20 deletions

View File

@ -40,12 +40,9 @@ def gen_point():
def distance(a, b, c):
try:
nom = abs((b.y - a.y) * c.x - (b.x - a.x) * c.y + b.x * a.y - b.y * a.x)
den = sqrt((b.y - a.y) ** 2 + (b.x - a.x) ** 2)
return nom / den
except ZeroDivisionError:
return 0
nom = abs((b.y - a.y) * c.x - (b.x - a.x) * c.y + b.x * a.y - b.y * a.x)
den = sqrt((b.y - a.y) ** 2 + (b.x - a.x) ** 2)
return nom / den
def is_left(a: Point, b: Point, c: Point):
@ -78,25 +75,22 @@ def find_hull(points: Set[Point], p: Point, q: Point, hull: Set[Point]):
if not points:
return
farthest = max(points, key=lambda point: distance(p, q, point))
farthest = max(points, key=lambda point: abs(distance(p, q, point)))
hull.add(farthest)
points.remove(farthest)
s1 = {point
for point in points
if not is_left(p, farthest, point)}
print("--")
print(s1)
find_hull({po for po in points if not is_left(p, farthest, po)},
p,
farthest,
hull)
s2 = {point
for point in points
if not is_left(farthest, q, point)}
print(s2)
find_hull(s1, p, farthest, hull)
find_hull(s2, farthest, q, hull)
find_hull({po for po in points if not is_left(farthest, q, po)},
farthest,
q,
hull)
peepees = {gen_point() for _ in range(11)}
peepees = {gen_point() for _ in range(30)}
hulliees = quick_hull(peepees)
display(peepees, hulliees)