File tree Expand file tree Collapse file tree 4 files changed +43
-12
lines changed Expand file tree Collapse file tree 4 files changed +43
-12
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ def main():
30
30
print ("Triangle contains (0,0)" )
31
31
else :
32
32
print ("Triangle dosen't contain (0,0)" )
33
+ ch = raw_input ("Do you want to Plot the Triangle and the (0,0) point? type (yes) or (not): " )
33
34
poss_trian .display_triangle_and_test_point (pt0 )
34
35
35
36
Original file line number Diff line number Diff line change @@ -26,7 +26,10 @@ def area(self):
26
26
+ (self .pt3 .get_x ()* (self .pt1 .get_y ()- self .pt2 .get_y ()))))
27
27
28
28
# True if point inside the triangle else False
29
- # https://www.youtube.com/watch?v=H9qu9Xptf-w
29
+ '''
30
+ Input : the point we want to test
31
+ Output : True if the point is in our triagnle else False
32
+ '''
30
33
def check_pt_triangle (self , pt_test ):
31
34
tr1 = Triangle (pt_test , self .pt1 , self .pt2 )
32
35
tr2 = Triangle (pt_test , self .pt2 , self .pt3 )
Original file line number Diff line number Diff line change 2
2
from plane import *
3
3
import numpy as np
4
4
import matplotlib .pyplot as plt
5
- import time
6
- RANGE_XY = 1000
5
+
6
+ #CHANGE IF YOU WANT THE RANGE OF NUMBERS TO RANDOM GENERATE Points
7
+ RANGE_XY = 100000
7
8
def parse_input ():
8
9
points = []
9
10
ch = raw_input ("To autogenerate write ->AUTO<- else just type something: " )
@@ -34,13 +35,32 @@ def main():
34
35
choice = raw_input ("Type (1) for Incremental / Type (2) for Gift Wrap: " )
35
36
while True :
36
37
if choice == "1" :
37
- plane .incremental_convex_hull ()
38
+ hull = plane .incremental_convex_hull ()
39
+ if hull is None :
40
+ print "Couldn't compute Convex Hull"
41
+ return
42
+ print ("**Hull Points**" )
43
+ for pt in hull :
44
+ pt .print_point ()
45
+ ch = raw_input ("Do you want to Plot points with the Convex Hull? type (yes) or (no): " )
46
+ if ch == "yes" :
47
+ plane .display_hull (hull )
38
48
break
39
49
elif choice == "2" :
40
- plane .gift_wrap_convex_hull ()
50
+ hull = plane .gift_wrap_convex_hull ()
51
+ if hull is None :
52
+ print "Couldn't compute Convex Hull"
53
+ return
54
+ print ("**Hull Points**" )
55
+ for pt in hull :
56
+ pt .print_point ()
57
+ ch = raw_input ("Do you want to Plot points with the Convex Hull? type (yes) or (no): " )
58
+ if ch == "yes" :
59
+ plane .display_hull (hull )
41
60
break
42
61
else :
43
62
print ("Wrong input Please choose again" )
63
+ break
44
64
45
65
if __name__ == "__main__" :
46
66
main ()
Original file line number Diff line number Diff line change @@ -89,12 +89,16 @@ def find_left_most_pt(self):
89
89
def sort_function (self ,point ):
90
90
return point .get_x ()
91
91
92
+ '''
93
+ Input : The already Points from the input of the program
94
+ Retunrs a list of Points with the hull points
95
+ '''
92
96
def incremental_convex_hull (self ):
93
97
lower_hull = []
94
98
upper_hull = []
95
99
96
- if len (self .points ) <= 1 :
97
- return self . points
100
+ if len (self .points ) <= 2 :
101
+ return None
98
102
99
103
#sorting list based on x coord {max -> min}
100
104
self .points = sorted (self .points ,key = self .sort_function , reverse = True )
@@ -136,15 +140,19 @@ def incremental_convex_hull(self):
136
140
upper_hull .append (self .points [idx ])
137
141
138
142
hull = lower_hull + upper_hull
139
- self .display_hull (hull )
140
- return
141
-
143
+ return hull
142
144
145
+ '''
146
+ Input : The already Points from the input of the program
147
+ Retunrs a list of Points with the hull points
148
+ '''
143
149
def gift_wrap_convex_hull (self ):
144
150
hull_points = []
145
151
#find leftmost point
146
152
left_pt = self .find_left_most_pt ()
147
153
total_points = len (self .points )
154
+ if total_points <= 2 :
155
+ return None
148
156
cr_pt = left_pt
149
157
while True :
150
158
hull_points .append (self .points [cr_pt ])
@@ -157,5 +165,4 @@ def gift_wrap_convex_hull(self):
157
165
cr_pt = curr_pt
158
166
if cr_pt == left_pt :
159
167
break
160
- self .display_hull (hull_points )
161
- return
168
+ return hull_points
You can’t perform that action at this time.
0 commit comments