Skip to content

The Polygon Object

Justin edited this page Mar 10, 2022 · 1 revision

Polygons are a core feature of cgal and there are many ways of constructing them.

A number of factory methods are provided.

//create a box polygon from the min max box values.
var box = PolygonFactory<EIK>.CreateBox(-1, 1);

//create a polygon circle at the origin with a radius of 4 and 16 sides segments.
var circle = PolygonFactory<EIK>.CreateCircle(point2d.Zero, 4, 16);

For most of the algorithms in cgal the polygon has to meet certain requirements. These are generally that the polygon is simple and counter clock wise. If this is not the case the algorithm may crash cgal. These values can be checked and are cached.

if(poly.IsSimple && poly.IsCCW)
{
    //do something 
}

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

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

The polygon 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 Polygon2<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);
Clone this wiki locally