Link to home
Start Free TrialLog in
Avatar of youse_libe
youse_libe

asked on

Need an algorithm

I need an algorithm to find out if a point is inside a shape defined by a bunch of coordinate points.  The shape might not be a standard polygon - it might be a star or similar shape that turns in on itself.

Any help appreciated.
Avatar of ozo
ozo
Flag of United States of America image

Count how many times a ray from the point to infinity intersects a side of polygon.
Avatar of Lischke
Lischke

ozo is a bit short here, but he mentioned the usual approach:

1) create a vector from the given point and a point which is guaranteed to lie outside the polygon (direction doesn't matter
2) go through all edges in the polygon and check if they cross the vector created in 1)
3) if the number of intersections is equal then the given point is not in the polygon otherwise it is

Ciao, Mike
Oops, it should read:

3) if the number of intersections is even then...

Ciao, Meike
Avatar of youse_libe

ASKER

ok, I see.

Now, could you just tell me what kind of math I need to know to do this calculation.  I've only had through calculus, long ago.  I don't think I've had anything that will do geometry like this.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you