Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

DZone's Guide to

# Point Inside A Polygon //JavaScript Function

·
Free Resource

Comment (0)

Save
{{ articles[0].views | formatCount}} Views
```
Checks whether a point is inside a polygon.

[UPDATED CODE AND HELP CAN BE FOUND HERE: Point Inside a Polygon]

```
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/math/is-point-in-poly [v1.0]

function isPointInPoly(poly, pt){
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y))
&& (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)
&& (c = !c);
return c;
}
```

Example

```

//<![CDATA[

points = [
{x: 0, y: 0},
{x: 0, y: 50},
{x: 50, y: 10},
{x: -50, y: -10},
{x: 0, y: -50},
{x: 0, y: 0}
];

alert(isPointInPoly(points, {x: 10, y: 10}) ? "In" : "Out");

//]]>

```
```
Topics:

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Opinions expressed by DZone contributors are their own.

### {{ parent.tldr }}

{{ parent.urlSource.name }}