I'm looking for an efficient algorithm for handling 2D dynamic rectilinear convex hulls.
I've coded up a static algorithm, but while it works in most cases, it doesn't work in all, so I'm also looking for resources on static rectilinear convex hulls. Wikipedia has some research papers on algorithms, but I can't access them. So looking for other sources or help writing up the code.
Any help would be appreciated, an algorithm in Python, most appreciated.
Current static Code:
def stepped_hull(points, is_sorted=False, return_sections=False):
# May be equivalent to the orthogonal convex hull
if not is_sorted:
points = sorted(set(points))
if len(points) <= 1:
return points
# Get extreme y points
min_y = min(points, lambda p:p[1])
max_y = max(points, lambda p:p[1])
points_reversed = list(reversed(points))
# Create upper section
upper_left = build_stepped_upper(points, max_y)
upper_right = build_stepped_upper(points_reversed, max_y)
# Create lower section
lower_left = build_stepped_lower(points, min_y)
lower_right = build_stepped_lower(points_reversed, min_y)
# Correct the ordering
lower_right.reverse()
upper_left.reverse()
if return_sections:
return lower_left, lower_right, upper_right, upper_left
# Remove duplicate points
hull = OrderedSet(lower_left + lower_right + upper_right + upper_left)
return list(hull)
def build_stepped_upper(points, max_y):
# Steps towards the highest y point
section = [points[0]]
if max_y != points[0]:
for point in points:
if point[1] >= section[-1][1]:
section.append(point)
if max_y == point:
break
return section
def build_stepped_lower(points, min_y):
# Steps towards the lowest y point
section = [points[0]]
if min_y != points[0]:
for point in points:
if point[1] <= section[-1][1]:
section.append(point)
if min_y == point:
break
return section