Skip to content

Commit 455998d

Browse files
author
msiampou
committed
added cross
1 parent 2b5a1a1 commit 455998d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

part1/src/ex3_ex4/plane.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def ort(self, pt1 , pt2, r):
4646
else:
4747
return CCW
4848

49+
def cross(self, pt1 , pt2, r):
50+
v = ((pt2.get_x()-pt1.get_x())*(r.get_y()-pt2.get_y())
51+
-(pt2.get_y()-pt1.get_y())*(r.get_x()-pt2.get_x()))
52+
if v <= 0:
53+
return CW
54+
else:
55+
return CCW
56+
4957
def display_hull(self, hull_points):
5058
if hull_points == []:
5159
print("No points on the hull list to display")
@@ -113,25 +121,26 @@ def incremental_convex_hull(self):
113121
# culculating lower hull #
114122
for idx in range(N):
115123
#print idx
116-
while len(lowerHull) >= 2 and \
117-
(self.ort(lowerHull[-2], lowerHull[-1], self.points[idx]) == CCW or \
118-
self.ort(lowerHull[-2], lowerHull[-1], self.points[idx]) == COLINEAR):
124+
while len(lowerHull) >= 2 and self.cross(lowerHull[-2], lowerHull[-1], self.points[idx]) == CW:
119125
lowerHull.pop()
120126
lowerHull.append(self.points[idx])
121127

122128
# culculating upper hull #
123129
self.points.reverse()
124130
#self.print_plane()
125131
for idx in range(N):
126-
while len(upperHull) >= 2 and \
127-
(self.ort(lowerHull[-2], lowerHull[-1], self.points[idx]) == CCW or \
128-
self.ort(lowerHull[-2], lowerHull[-1], self.points[idx]) == COLINEAR):
132+
while len(upperHull) >= 2 and self.cross(lowerHull[-2], lowerHull[-1], self.points[idx]) == CW:
129133
upperHull.pop()
130134
upperHull.append(self.points[idx])
131135

132136
#pop common point
133137
lowerHull.pop()
134138
hull = lowerHull + upperHull
139+
for point in lowerHull:
140+
point.print_point()
141+
print "\n"
142+
for point in upperHull:
143+
point.print_point()
135144
self.display_hull(lowerHull)
136145
self.display_hull(upperHull)
137146
self.display_hull(hull)

part1/src/ex3_ex4/plane.pyc

327 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)