Determining polygon intersection and containment

前端 未结 4 1712
借酒劲吻你
借酒劲吻你 2021-02-05 18:09

I have a set of simple (no holes, no self-intersections) polygons, and I need to check that they don\'t intersect each other (one can be entirely contained in another; that is o

4条回答
  •  遥遥无期
    2021-02-05 18:29

    To test for intersections you could use my freeware clipper library: http://sourceforge.net/projects/polyclipping/ .

    To test for containment, first exclude intersections as above. Then use Clipper again adding all the polygons - Clipper.AddPolygon(). Then perform a Union (boolean OR) operation on the polygons - Clipper.Execute(ctUnion, solution). If the Clipper.ForceAlternateOrientation property is true, Clipper will return in the solution outer polygons in clockwise orientation and contained polygons (holes) in counter-clockwise orientation. It should then be a simple matter of testing polygon orientations and applying a PointInPolygon from one vertex in a counter-clockwise polygon against the other clockwise polygons.

提交回复
热议问题