Skip to content

Polygon Offset

Justin edited this page Mar 11, 2022 · 8 revisions

CGAL provides the polygon offset algorithm for polygons and polygons with holes.

This is provided through the PolygonOffset2 class of which a static instance can be used as follows.


//Create a polygon to offset.
var poly = PolygonFactory<EIK>.KochStar(30, 3);

//Get the instance to the offset algorithm.
var instance = PolygonOffset2<EIK>.Instance;

//If you know the input is good then checking 
//can be disabled which can increase perform.
//instance.CheckInput = false;

//The amount to offset.
double amount = 0.5;

//Create in interior offset.
var interior = new List<Polygon2<EIK>>();
instance.CreateInteriorOffset(poly, amount, interior);

for(int i = 0; i < interior.Count; i++)
    interior[i].Print();

//Create the exterior offset.
var exterior = new List<Polygon2<EIK>>();
instance.CreateExteriorOffset(poly, amount, exterior);

//The first polygon is the bounding box so ignore.
for(int i = 1; i < exterior.Count; i++)
    exterior[i].Print();

Below is a image of the exterior offset of the Koch start.

PolygonOffset

The PolygonOffset algorithm also provides methods to extract the polygons skeleton as follows.

//Create a polygon.
var polygon = PolygonFactory<EIK>.KochStar(30, 3);

//Get the instance to the offset algorithm.
var instance = PolygonOffset2<EIK>.Instance;

//The skeleton is return as a array of segments.
var skeleton = new List<Segment2d>();
instance.CreateInteriorSkeleton(polygon, false, skeleton);

Below is a image of the skeleton of the Koch star.

PolygonSkeleton

Clone this wiki locally