Skip to content

Commit 5c34e2a

Browse files
committed
finito
1 parent fa920bb commit 5c34e2a

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

part1/src/ex1/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def main():
3030
print ("Triangle contains (0,0)")
3131
else:
3232
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): ")
3334
poss_trian.display_triangle_and_test_point(pt0)
3435

3536

part1/src/ex1/triangle.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def area(self):
2626
+(self.pt3.get_x()*(self.pt1.get_y()-self.pt2.get_y()))))
2727

2828
# 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+
'''
3033
def check_pt_triangle(self, pt_test):
3134
tr1 = Triangle(pt_test, self.pt1, self.pt2)
3235
tr2 = Triangle(pt_test, self.pt2, self.pt3)

part1/src/ex3_ex4/main.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from plane import *
33
import numpy as np
44
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
78
def parse_input():
89
points = []
910
ch = raw_input("To autogenerate write ->AUTO<- else just type something: ")
@@ -34,13 +35,32 @@ def main():
3435
choice = raw_input("Type (1) for Incremental / Type (2) for Gift Wrap: ")
3536
while True:
3637
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)
3848
break
3949
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)
4160
break
4261
else:
4362
print ("Wrong input Please choose again")
63+
break
4464

4565
if __name__ == "__main__":
4666
main()

part1/src/ex3_ex4/plane.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ def find_left_most_pt(self):
8989
def sort_function(self,point):
9090
return point.get_x()
9191

92+
'''
93+
Input : The already Points from the input of the program
94+
Retunrs a list of Points with the hull points
95+
'''
9296
def incremental_convex_hull(self):
9397
lower_hull = []
9498
upper_hull = []
9599

96-
if len(self.points) <= 1:
97-
return self.points
100+
if len(self.points) <= 2:
101+
return None
98102

99103
#sorting list based on x coord {max -> min}
100104
self.points = sorted(self.points,key = self.sort_function, reverse = True)
@@ -136,15 +140,19 @@ def incremental_convex_hull(self):
136140
upper_hull.append(self.points[idx])
137141

138142
hull = lower_hull + upper_hull
139-
self.display_hull(hull)
140-
return
141-
143+
return hull
142144

145+
'''
146+
Input : The already Points from the input of the program
147+
Retunrs a list of Points with the hull points
148+
'''
143149
def gift_wrap_convex_hull(self):
144150
hull_points = []
145151
#find leftmost point
146152
left_pt = self.find_left_most_pt()
147153
total_points = len(self.points)
154+
if total_points <= 2:
155+
return None
148156
cr_pt = left_pt
149157
while True:
150158
hull_points.append(self.points[cr_pt])
@@ -157,5 +165,4 @@ def gift_wrap_convex_hull(self):
157165
cr_pt = curr_pt
158166
if cr_pt == left_pt:
159167
break
160-
self.display_hull(hull_points)
161-
return
168+
return hull_points

0 commit comments

Comments
 (0)