libgeos / geos

Geometry Engine, Open Source
https://libgeos.org
GNU Lesser General Public License v2.1
1.21k stars 362 forks source link

Get voronoi diagram edges excluding those going to infinity #874

Closed theroggy closed 1 year ago

theroggy commented 1 year ago

One of the ways an approximate centerline/medial axis of a polygon can be calculated is by using the edges of a voronoi diagram of the coordinates of the polygon.

For this purpose though, the edges going to infinity are not needed and need to be filtered out. Because this filtering takes some processing when done afterwards, I wondered if it is known in internal structures of geos which edges are going to infinity or not?

If it is known, would it be possible/easy to offer the choice in GEOSVoronoiDiagram (e.g. via an extra flag) to only return the edges not going to infinity instead of all edges?

dr-jts commented 1 year ago

In fact it's not just "edges going to infinity" which need to be removed. For concave polygons there can be edges well within the convex hull of the polygon which are not candidate medial axis edges. For example: image

In any case, the current Voronoi implement works on points only, so it does not have any information about the edges of the polygon between the vertex points. So the only way to remove them is to run a contains query (which is probably what you are already doing).

theroggy commented 1 year ago

In fact it's not just "edges going to infinity" which need to be removed. For concave polygons there can be edges well within the convex hull of the polygon which are not candidate medial axis edges.

True, for concave cases filtering edges going to infinity isn't enough... so extra filtering will indeed always stay necessary.

In any case, the current Voronoi implement works on points only, so it does not have any information about the edges of the polygon between the vertex points. So the only way to remove them is to run a contains query (which is probably what you are already doing).

OK, no problem, thanks for the clarification. I'm indeed doing a contains query now...