Jump to content

Welcome to Gaming On Steroids Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
Photo

XPolygon - Extended Polygon Library

polygon geometry library xpolygon clipper

  • Please log in to reply
2 replies to this topic

#1
Ark223

Ark223

    Advanced Member

  • Members
  • 394 posts

OunLF9T.png

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


  • 5

#2
Zanthir

Zanthir

    Member

  • Members
  • 15 posts
  • LocationMontreal

God damn your nuts xd 


  • 1

#3
Aristo

Aristo

    You donut

  • Moderator
  • 12,717 posts
  • LocationSomewhere over the rainbow

Thanks for your big effort, I've added it to the DB.


  • 0




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users