Point Inside Polygon - Ray Method
- From: "Narek Saribekyan" <narek.saribekyan@xxxxxxxxx>
- Date: 19 Apr 2006 07:50:18 -0700
Here is the most known method to test if point is inside polygon.
p polygon
n number of vertices in polygon
q point
RightHorizontalRayIntersection(q,u,v) tests if horizontal ray starting
from point q (in right direction) intersects a segment (u,v).
bool IsPointInsidePolygon( P *p,int n,P q ) {
int i,j,c=0;
for (i=0,j=n-1; i<n; j=i++) // Considering all segments (p[i],p[j])
if (RightHorizontalRayIntersection( q,p[i],p[j] )) c++;
return c%2;
}
There are some special cases.
1. Ray r intersects a segment in one of it's vertices.
2. Ray r is collinear to one of p's segments.
3. Point q is lying on one of p's segments.
I need a good method to avoid this special cases and/or other method to
solve this problem.
Thanks in advance,
Narek Saribekyan
.
- Follow-Ups:
- Re: Point Inside Polygon - Ray Method
- From: Christer Ericson
- Re: Point Inside Polygon - Ray Method
- From: Keith A. Lewis
- Re: Point Inside Polygon - Ray Method
- Prev by Date: Re: Fermat's Last Secret
- Next by Date: Proposta para você!
- Previous by thread: Olber's paradox and number density
- Next by thread: Re: Point Inside Polygon - Ray Method
- Index(es):