View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Codespike  Members

Posted 08 October 2001 - 02:52 PM

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.

### #2Oluseyi  Members

Posted 08 October 2001 - 03:03 PM

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.

### #3grhodes_at_work  Members

Posted 09 October 2001 - 03:19 AM

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.

### #4IStrikerI  Members

Posted 12 October 2001 - 02:51 AM

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.