File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments