Skip to content

Commit

Permalink
Add polygon clipping ops to utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
omersahintas committed Oct 13, 2021
1 parent 87dbd1b commit 6d95eec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions p3iv_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-numpy</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-scipy</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-simplejson</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-shapely</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-numpy</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-scipy</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-simplejson</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-shapely</exec_depend>


<export>
Expand Down
18 changes: 18 additions & 0 deletions p3iv_utils/src/p3iv_utils/polygon_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is part of the P3IV Simulator (https://github.com/fzi-forschungszentrum-informatik/P3IV),
# copyright by FZI Forschungszentrum Informatik, licensed under the BSD-3 license (see LICENSE file in main directory)

import numpy as np
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon


class PolygonCalculation(object):
def __init__(self, right_bound, left_bound):
"""Create a shapely-polygon"""
p = np.vstack([right_bound, left_bound[::-1]])
self.polygon = Polygon(p)

def __call__(self, point_xy):
"""Check if point is inside polygon. Return boolean"""
point = Point(point_xy[0], point_xy[1])
return self.polygon.contains(point)

0 comments on commit 6d95eec

Please sign in to comment.