8000 Working on a convex hull algorithm. · pythonpeixun/practice-python@333be74 · GitHub
[go: up one dir, main page]

Skip to content

Commit 333be74

Browse files
committed
Working on a convex hull algorithm.
1 parent 47cc6ff commit 333be74

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

convex-hull/convex-hull.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from collections import namedtuple
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
6+
Point = namedtuple('Point', 'x y')
7+
8+
9+
class ConvexHull(object):
10+
points = []
11+
12+
def __init__(self):
13+
pass
14+
15+
def add(self, point):
16+
self.points.append(point)
17+
18+
def display(self):
19+
x = [p.x for p in self.points]
20+
y = [p.y for p in self.points]
21+
22+
plt.plot(x, y, marker='D', linestyle='None')
23+
plt.title('Convex Hull')
24+
plt.show()
25+
26+
27+
def main():
28+
ch = ConvexHull()
29+
ch.add(Point(1, 4))
30+
ch.add(Point(3, 12))
31+
ch.add(Point(5, 7))
32+
ch.add(Point(3, 6))
33+
ch.add(Point(12, 19))
34+
ch.add(Point(4, 8))
35+
ch.add(Point(5, 7))
36+
ch.add(Point(9, 3))
37+
ch.add(Point(9, 6))
38+
ch.add(Point(10, 6))
39+
ch.add(Point(8, 16))
40+
ch.add(Point(2, 6))
41+
42+
ch.display()
43+
44+
45+
if __name__ == '__main__':
46+
main()

0 commit comments

Comments
 (0)
0