Skip to content

The Polygon With Holes Object

Justin edited this page Mar 10, 2022 · 1 revision

To create a polygon with a hole in CGAL a PolygonWithHoles2 object must be created which consists a counter clockwise polygon for the boundary and any number of clockwise polygons for holes.

Holes must be contained in the boundary and not intersect any other holes in the polygon.

A polygon with holes can be created like so.

//Create the boundary polygon.
var pwh = new PolygonWithHoles2<EIK>(boundaryPoints);

//Create a hole polygon.
var hole = new Polygon2<EIK>(holePoints);

//if unsure hole is valid this utility function can be used to check.
if(PolygonWithHoles2.IsValidHole(pwh, hole))
{
    //Add hole
    pwn.AddHole(hole);
}

Note that only polygons can be added as holes and not a PolygonWithHoles2 object. This means there is not support for nested polygons with holes.

Certain algorithms will only work with certain kernels. The polygon with holes can be converted like so.

var eek_poly = eik_poly.Convert<EEK>();

The polygon with holes object also contains some helpful utility functions. These are often part of a larger suit of algorithms which will be covered in their own sections.

A few examples are as follows.

//create a polygon from some points.
var poly = new PolygonWithHoles2<EEK>(points);

//simplify the polygon with a threshold.
poly.Simpliy(0.5);

//find the intersection with a second polygon.
var poly3 = poly.Intersection(poly2);

//triangulate the polygon.
poly.Triangulate(indices);

Add below a image of a Koch star used for debugging and created like so.

//Create the star polygon that will be the boundary.
var koch = PolygonFactory<EIK>.KochStar(30, 3);

//Create a circle for the hole.
var hole = PolygonFactory<EIK>.CreateCircle(5, 32);

//Make hole cw.
hole.Reverse();

//Create the PolygonWithHole from the start and circle
var pwh = new PolygonWithHoles2<EIK>(koch);
pwh.AddHole(hole);

KockStar

Clone this wiki locally