Hi,
how can i test a point is inside a regular polygon or not?
i was trying to think this way:
#take a random point far away
#make a line with the test point and this random point
#check for intersection between this line and all the edges and count it
#if the count is odd then the point is inside otherwise outside
but i got stuck in the case where my test line will intersect in any of the
vertex of the polygon, now how can i know where the point is?
can anyone help me from here? thanks...
Help on testing point inside a polygon
Moderator: Board moderators
-
- Experienced poster
- Posts: 183
- Joined: Thu Nov 11, 2004 12:35 pm
- Location: AIUB, Bangladesh
Help on testing point inside a polygon
Jalal : AIUB SPARKS
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
You can use the 'winding number' method, which is described here http://softsurfer.com/Archive/algorithm ... m_0103.htm.
This is a great site for other geometry algorithms too.
This is a great site for other geometry algorithms too.
-
- Experienced poster
- Posts: 183
- Joined: Thu Nov 11, 2004 12:35 pm
- Location: AIUB, Bangladesh
Hi, little joey and Darko , thanks for the reply.
ya, the link is rich and i hope my problem will be fixed from there.
ya, the link is rich and i hope my problem will be fixed from there.
well Darko, i thought about that one, but what if the point is outside the polygon? then odd count means it is inside the polygon, isn't it?Well, when you go through edges, if they are (p1,p2), you can do >p1, <=p2, that way you count the vertex only once? In other words, consider an edge as a half-open interval (p1,p2] (or something like that)
Code: Select all
polygon : (0, 0), (10, 0), (10, 10), (0, 10)
test point 1: (10, -10) and unfortunately if i pick another random point (-10, 10)
test point 2: (5,5) and unfortuantely this time my random point is (1000,1000)
Jalal : AIUB SPARKS
http://www.exaflop.org/docs/cgafaq/cga2.html
(no special cases)
(no special cases)