By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

If a given point in the plane lies inside, outside, or on the boundary of a polygon ?

P: 1
Hello friend.
I want to write a program whether a given point in the plane lies inside, outside, or on the boundary of a polygon. I have found this interesting website which shows 2 ways of doing that. i.e InsidePolygon() and pnpoly()

http://local.wasp.uwa.edu.au/~pbourk...ry/insidepoly/

But these Algo/code don't detect if the input pt is on the boundary of a polygon?

Can you guys help me in that part of code/algo?

Your help is much appreciated.

~ Jenny
Sep 15 '10 #1
Share this Question
Share on Google+
1 Reply


100+
P: 687
It requires to check is F(x,y)==0 for F describing a segment of the polygon, but as floating point calculations are imprecise, you will have to determine what precision is required and check abs(F(x,y)) < e instead.
it seems that relevand portion is
if (p1.x == p2.x || p.x <= xinters)
and you could use if (fabs(p.x-xinters)<epsilon) but this will not work on nearly horizontal segments.
Sep 15 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.