Wolfram Library Archive

All Collections Articles Books Conference Proceedings
Courseware Demos MathSource Technical Notes
Title Downloads

Ray Tracing for Point in Polygon Problem

Raja Kountanya
Revision date


In computational geometry, there is a classical problem of partitioning a set of points in a 2D into those enclosed by a polygon and those outside. Currently, the best way is supposed to be a ray tracing method where a ray is drawn from a candidate point in the positive X-direction and number of intersections with the polygon is counted. If the number is odd, the point is inside, if it is even, it is outside.

In Mathematica 8.0 (or probably earlier), there is a new facility to get coordinates of points inside a 2D plot. With a right-mouse click inside the plot, choose "Get Coordinates", then draw the boundary of the area desired. Points are chosen which form the polygon to divide. Then Ctrl+C copies the coordinates of the points. Assign it to the tlist in the code below. Then run the whole code.

*Mathematics > Geometry > Computational Geometry
*Mathematics > Geometry > Plane Geometry

Point in Polygon, Computational Geometry
Downloads Download Wolfram CDF Player

RayTracing.nb (249.4 KB) - Mathematica Notebook [for Mathematica 8.0]