This commit is contained in:
Casper 2018-09-20 16:54:47 +02:00
parent 1bbb5d9cf3
commit 55bf40ddf6

View File

@ -40,12 +40,9 @@ def gen_point():
def distance(a, b, c): 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)
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)
den = sqrt((b.y - a.y) ** 2 + (b.x - a.x) ** 2) return nom / den
return nom / den
except ZeroDivisionError:
return 0
def is_left(a: Point, b: Point, c: Point): 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: if not points:
return 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) hull.add(farthest)
points.remove(farthest)
s1 = {point find_hull({po for po in points if not is_left(p, farthest, po)},
for point in points p,
if not is_left(p, farthest, point)} farthest,
print("--") hull)
print(s1)
s2 = {point find_hull({po for po in points if not is_left(farthest, q, po)},
for point in points farthest,
if not is_left(farthest, q, point)} q,
print(s2) hull)
find_hull(s1, p, farthest, hull)
find_hull(s2, farthest, q, hull)
peepees = {gen_point() for _ in range(11)} peepees = {gen_point() for _ in range(30)}
hulliees = quick_hull(peepees) hulliees = quick_hull(peepees)
display(peepees, hulliees) display(peepees, hulliees)