Update point_in_poly func

For better handling of non-convex surfaces
parent bc2a277f
No preview for this file type
 ... ... @@ -133,18 +133,32 @@ def point_in_poly(point, poly): qip2_r = Vector2D(10000, 1) # quasi-infinite point 2 to the right qip1_l = Vector2D(-10000, 0) # quasi-infinite point 1 to the left qip2_l = Vector2D(-10000, 1) # quasi-infinite point 2 to the left qip1_u = Vector2D(0, 10000) # quasi-infinite point 1 to the right qip2_u = Vector2D(1, 10000) # quasi-infinite point 2 to the right qip1_d = Vector2D(0, -10000) # quasi-infinite point 1 upwards qip2_d = Vector2D(1, -10000) # quasi-infinite point 2 downwards test_poly_r = Polygon2D([point, qip1_r, qip2_r])#.order_points('upperleftcorner') # maybe we wouldn't need this anyway test_poly_l = Polygon2D([point, qip1_l, qip2_l])#.order_points('upperleftcorner') # maybe we wouldn't need this anyway test_poly_u = Polygon2D([point, qip1_u, qip2_u]) test_poly_d = Polygon2D([point, qip1_d, qip2_d]) #poly = poly.order_points('upperleftcorner') # maybe we wouldn't need this anyway inter_r = poly.intersect(test_poly_r) inter_l = poly.intersect(test_poly_l) inter_u = poly.intersect(test_poly_u) inter_d = poly.intersect(test_poly_d) if len(inter_r) == 0: inter_r.append() if len(inter_l) == 0: inter_l.append() if len(inter_u) == 0: inter_u.append() if len(inter_d) == 0: inter_d.append() no_inter_r = len(inter_r) no_inter_l = len(inter_l) return True if no_inter_r == 3 or no_inter_l == 3 else False # we will see how robust this is # check this again later no_inter_u = len(inter_u) no_inter_d = len(inter_d) return True if no_inter_r == 3 or no_inter_l == 3 or no_inter_u == 3 or no_inter_d == 3 else False # we will see how robust this is # check this again later def gridpoints_in_poly_2d(grid_2d, poly_2d): "Returns a list of points, that are inside a 2d poly. Takes a meshgrid (made with grid_2d) and a 2d poly as input" ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!