InPoly: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Welcome| desc=Checks if a point is inside a polygon defined by multiple vertices.| params=<syntaxhighlight lang="lua">(px, py, x1, y1, x2, y2, ...)</syntaxhighlight> <poem>::px, py: The coordinates of the point to be checked. ::x1, y1: The coordinates of the first vertex of the polygon. ::x2, y2: The coordinates of the second vertex of the polygon. ::...: The coordinates of subsequent vertices of the polygon.</poem>| retvals=Returns `true` if the point is inside the po...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
params=<syntaxhighlight lang="lua">(px, py, x1, y1, x2, y2, ...)</syntaxhighlight> | params=<syntaxhighlight lang="lua">(px, py, x1, y1, x2, y2, ...)</syntaxhighlight> | ||
<poem>::px, py: The coordinates of the point to be checked. | <poem>::px, py: The coordinates of the point to be checked. | ||
::x1, y1: The coordinates of the first vertex of the polygon. | ::x1, y1: The coordinates of the first vertex of the polygon as floating points. | ||
::x2, y2: The coordinates of the second vertex of the polygon. | ::x2, y2: The coordinates of the second vertex of the polygon as floating points. | ||
::...: The coordinates of subsequent vertices of the polygon.</poem>| | ::...: The coordinates of subsequent vertices of the polygon. | ||
retvals=Returns | ::You need to provide atleast 3 vertices to this function.</poem>| | ||
example=<source lang="lua"> | retvals=Returns true if the point is inside the polygon, otherwise returns false.| | ||
example=[[File:InPoly.png|thumb|]] | |||
<source lang="lua"> | |||
local inside = InPoly(3, 4, 0, 0, 6, 0, 6, 6, 0, 6); | local inside = InPoly(3, 4, 0, 0, 6, 0, 6, 6, 0, 6); | ||
if(inside) | if(inside) |
Latest revision as of 07:54, 1 October 2024
Description:
Checks if a point is inside a polygon defined by multiple vertices.
Parameters:
(px, py, x1, y1, x2, y2, ...)
px, py: The coordinates of the point to be checked.
x1, y1: The coordinates of the first vertex of the polygon as floating points.
x2, y2: The coordinates of the second vertex of the polygon as floating points.
...: The coordinates of subsequent vertices of the polygon.
You need to provide atleast 3 vertices to this function.
Return Values:
Returns true if the point is inside the polygon, otherwise returns false.
Example
local inside = InPoly(3, 4, 0, 0, 6, 0, 6, 6, 0, 6); if(inside) print("The point (3,4) is inside the polygon."); else print("The point (3,4) is outside the polygon.");