Ray Tracing for Points in a Polygon

This Demonstration uses the ray tracing method to determine whether points on a plane lie inside or outside a given polygon.


  • [Snapshot]
  • [Snapshot]
  • [Snapshot]


In computational geometry, there is a classical problem of partitioning a set of points in 2D into those enclosed by a polygon and those outside. Currently, the best known way is a ray-tracing method, in which a ray is drawn from a candidate point in the positive direction and the 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 this Demonstration, starting with a simple triangle, you can add vertices to a polygon and drag them to see how the points are classified to be inside (green) or outside (red). Notice, however, that the ordering of the vertices is important, since the polygon is shaped by both position and ordering of the vertices.
[1] Wikipedia. "Point in Polygon." (Jun 1, 2016) en.wikipedia.org/wiki/Point_in_polygon.
[2] R. Kountanya. "Ray Tracing for Point in Polygon Problem" from Wolfram Library Archive—A Wolfram Web Resource. (Jun 1, 2016) library.wolfram.com/infocenter/MathSource/7780.
    • Share:

Embed Interactive Demonstration New!

Just copy and paste this snippet of JavaScript code into your website or blog to put the live Demonstration on your site. More details »

Files require Wolfram CDF Player or Mathematica.