
Polygon functions:
[1] AreaOfPolygon(<list, points> poly) - returns number
[2] CentroidOfPolygon(<list, points> poly) - returns point
[3] ClipPolygons(<list, points> poly1, <list, points> poly2, <string> operation) - returns list(s) of points
> operation = {"union", "intersection", "difference"}
[4] MovePolygon(<list, points> poly, <point> direction) - returns list of points
[5] GetPolygonSegments(<list, points> poly) - returns list of polygon segments
[6] IsPointInPolygon(<list, points> poly, <point> point) - returns boolean
[7] OffsetPolygon(<list, points> poly, <number> offset) - returns list of points
[8] PolygonContainsPolygon(<list, points> poly1, <list, points> poly2) - returns boolean
[9] PolygonIntersection(<list, points> poly1, <list, points> poly2) - returns list of points
[10] RotatePolygon(<list, points> poly, <number> angle) - returns list of points
Standard functions:
[1] Closest(<list, points> points, <point> point) - returns point
[2] ClosestPointOnSegment(<point> segment1, <point> segment2, <point> point) - returns point
[3] CrossProduct(<point> point1, <point> point2) - returns number
[4] Direction(<point> point1, <point> point2) - returns number
[5] Distance(<point> point1, <point> point2) - returns number
[6] DistanceSquared(<point> point1, <point> point2) - returns number
[7] DotProduct(<point> point1, <point> point2) - returns number
[8] Magnitude(<point> point1, <point> point2) - returns number
[9] MagnitudeSquared(<point> point1, <point> point2) - returns number
[10] Normalize(<point> point) - returns point
[11] Intersection(<point> point1, <point> point2, <point> point3, <point> point4) - returns point & boolean
> boolean - returns true if intersection exists for line segments
[12] IsPointOnSegment(<point> segment1, <point> segment2, <point> point) - returns boolean
Example usage:
local path1 = {
{x = 40, y = 40},
{x = 100, y = 200},
{x = 320, y = 160},
{x = 140, y = 60},
}
local path2 = {
{x = 230, y = 280},
{x = 260, y = 80},
{x = 400, y = 120},
{x = 360, y = 240},
}
local res1, res2 = XPolygon:ClipPolygons(path1, path2, "union")
local new = XPolygon:OffsetPolygon(res1, 15)
for i, point in ipairs(new) do print(point) end
print(XPolygon:AreaOfPolygon(new))
Download: https://raw.githubus...er/XPolygon.lua
Sign In
Create Account

Back to top
Report







