-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add polygon clipping ops to utilities
- Loading branch information
1 parent
87dbd1b
commit 6d95eec
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |