forked from wylloong/Global_path_planning_for_USV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeometryBase.py
35 lines (32 loc) · 1.08 KB
/
GeometryBase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
"""
Copyright(c) 2017, waylon
All rights reserved.
Distributed under the BSD license.
"""
from shapely.geometry import Polygon,Point
def point_in_polygon(point_x, point_y, polygonlist_x,polygonlist_y):
# Be careful about the Coordinate Translation.
point = Point(point_x,point_y)
i = 0
polygonlist = []
while i < len(polygonlist_x):
t = (polygonlist_x[i], polygonlist_y[i])
polygonlist.append(t)
i = i + 1
poly = Polygon(polygonlist)
return poly.contains(point)
if __name__=='__main__':
# The test point
polygonlist_x=[]
polygonlist_x.append(25.774252)
polygonlist_x.append(18.466465)
polygonlist_x.append(32.321384)
polygonlist_y = []
polygonlist_y.append(-80.190262)
polygonlist_y.append(-66.118292)
polygonlist_y.append(-64.75737)
result=point_in_polygon(27.254629577800088, -76.728515625,polygonlist_x,polygonlist_y)
print(result)
result=point_in_polygon(27.254629577800088, -74.928515625,polygonlist_x,polygonlist_y)
print(result)