• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# How do I detect if an object is inside or outside a polygon

## 3 posts in this topic

Imagine an n-sided polygon, does anyone know a general formula I can apply to detect if an object is within the polygon''s boundaries or outside? What I intend to use it for is to detect whether my mouse cursor is within a polygon or not.
0

##### Share on other sites
These things are called "inside tests". I posted on two methods a few moths ago; try searching on that term. If you don''t find anything, I''ll dig up the info and post again.

Hint: the two major methods are winding numbers and intersection count.
0

##### Share on other sites
A good web site for point-in-polygon tests:

http://www.acm.org/pubs/tog/editors/erich/ptinpoly/

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
0

##### Share on other sites
i know two methods:

1. calculate a plane for each egde of the polygon and test the point against them.

2. imagine a point where you know it IS outside of the polygon. then draw a line from the point you want to check to the point which lies outside the polygon. if this line crossed one edge the point is inside the polygon. if it crossed two edges the point is outside the polygon. if it crossed three edges the point is inside the polygon and so on. this also works for non convex polygons.
0