Polygon

Polygon type

Note: Polygon variable can be cast into a TPointArray in order to use it with TPointArray methods.


TPolygon.Bounds

function TPolygon.Bounds: TBox;

TPolygon.Mean

function TPolygon.Mean: TPoint;

Returns the mean, or rather the centroid of the polygon.


TPolygon.Area

function TPolygon.Area: Double;

Computes the area of the polygon.


TPolygon.IsConvex

function TPolygon.IsConvex: Boolean;

Returns if the polygon is convex, order does not matter. A concave polygon will return False.


TPolygon.Contains

function TPolygon.Contains(p: TPoint): Boolean;

Is the point in the polygon?


TPolygon.ContainsLine

function TPolygon.ContainsLine(p,q: TPoint): Boolean;

Returns True if the line fits within the bounds of the polygon. This is determined by checking if the line crosses any of the vertices.


TPolygon.NearestEdge

function TPolygon.NearestEdge(P: TPoint): TPoint

TPolygon.Expand

function TPolygon.Expand(Amount: Integer): TPolygon

TPolygon.Triangulate

function TPolygon.Triangulate(MinArea: Double = 0; MaxDepth: Int32 = 0): TTriangleArray;

Break the polygon into triangles, the smallest possible polygon. The order of the input does matter, if it fails, try to reverse the Poly with Poly.Reversed()

This is a custom algorithm by slacky, based around the concept of trimming “ears”, if you dont like the output, you may have luck with rolling the Polygon before calling.

Two default params exists as well, MinArea and MaxDepth, they work in tandom, MinArea parameter is for setting a minimum size of triangles added to result, and as this method works iteratively, removing triangles in a circle around the shape over and over, MaxDepth refers to the max number of rounds it has moved around the shape before it ignores MinArea paramater.


TPolygon.DouglasPeucker

function TPolygon.DouglasPeucker(Epsilon: Double): TPolygon;

Attempts to simplify the polygon by trimming vertices.


TPolygon.FurthestPoints

procedure TPolygon.FurthestPoints(out A,B: TPoint);

Returns the two points that are furthest away from eachother in a polygon.


TPolygon.Connect

function TPolygon.Connect: TPointArray;

Connects the polygon vertices in order to make a TPointArray bounding shape.