Reference · Deterministic 2D physics
pointInPolygonfunction
Whether (px, py) is inside the polygon (an even-odd test over its vertices, in order).
Import it
import { pointInPolygon } from "@johnmorrisdotca/karakuri/physics";
Definition
function pointInPolygon(px: number, py: number, polygon: readonly Vec[]): boolean
Parameters
| Name | Type | Description |
|---|---|---|
px | number | The horizontal coordinate of the point to test. |
py | number | The vertical coordinate of the point to test. |
polygon | readonly Vec[] | The polygon’s native vertices, in outline order. |
Returns
boolean
Whether (px, py) is inside the polygon (an even-odd test over its vertices, in order).
Examples
import { pointInPolygon } from "@johnmorrisdotca/karakuri/physics";
console.log(pointInPolygon(2,2,[{x:0,y:0},{x:5,y:0},{x:5,y:5},{x:0,y:5}]));trueWhat it prints (run when this page was built)