using ClipperLib; using System.Collections.Generic; //create a polygon with an existing contour Listpolygon = new List { new IntPoint(0, 0), new IntPoint(20, 0), new IntPoint(20, 20), new IntPoint(0, 20) }; //create a new contour (rectangle) to be added to the polygon List newContour = new List { new IntPoint(5, 5), new IntPoint(15, 5), new IntPoint(15, 15), new IntPoint(5, 15) }; //add the new contour to the existing polygon Polygon poly = new Polygon(); poly.AddContour(polygon, PolyType.ptSubject); poly.AddContour(newContour, PolyType.ptClip);
using ClipperLib; using System.Collections.Generic; //create a polygon with an existing contour ListThe package library used in these examples is ClipperLib, which is a C++/C# library for polygon clipping and offsetting.polygon = new List { new IntPoint(0, 0), new IntPoint(20, 0), new IntPoint(20, 20), new IntPoint(0, 20) }; //create a new contour (circle) to be added to the polygon as a hole List newContour = new List (); for (int i = 0; i < 360; i++) { double radians = i * Math.PI / 180; double x = 10 + Math.Cos(radians) * 5; double y = 10 + Math.Sin(radians) * 5; newContour.Add(new IntPoint((int)x, (int)y)); } //add the new contour as a hole to the existing polygon Polygon poly = new Polygon(); poly.AddContour(polygon, PolyType.ptSubject); poly.AddContour(newContour, PolyType.ptClip, true);