prochitecture / blosm

GNU General Public License v3.0
11 stars 3 forks source link

Question: detection if a polygon is inside a graph-cycle. #27

Open vvoovv opened 2 years ago

vvoovv commented 2 years ago

Which method is used to detect if a polygon is inside a graph-cycle?

polarkernel commented 2 years ago

Which method is used to detect if a polygon is inside a graph-cycle?

This is currently done inside of the pyGEOS subtraction cyclePoly = cyclePoly.difference(objPoly). When the polygon objPolyis outside of the graph-cycle cyclePoly, nothing happens, when it intersects the cycle, it gets subtracted and when it is completely inside the cycle, it is stored as a hole. However, pyGeos provides also other predicates, like for instance disjoint, when no subtraction is required, see here.

vvoovv commented 2 years ago

Wouldn't it be more efficient to use another method? For example the Point in polygon algorithms.

polarkernel commented 2 years ago

Wouldn't it be more efficient to use another method?

As long as the polygons are not strictly convex (which is not the case for our objects) it is not possible to decide this by point in polygon algorithms. The fastest way I know is to check for segment intersections (using a sweep line method) and, when there is no intersection, to test if one of the points is inside the other polygon. I am not sure if this would be much faster than what pyGEOS does.

vvoovv commented 2 years ago

As long as the polygons are not strictly convex (which is not the case for our objects) it is not possible to decide this by point in polygon algorithms.

Don't the "Ray casting" and "Winding number" algorithms work for concave polygons?

polarkernel commented 2 years ago

Don't the "Ray casting" and "Winding number" algorithms work for concave polygons?

Sure they work, but for concave polygons all points may be inside, but not the polygon:

2