Paths inside a Polygon

This Demonstration illustrates an algorithm for finding the shortest path that stays inside a polygon and connects two given interior points. Aside from the start and finish, such a path must go from reflex vertex to reflex vertex; thus you start by first making the graph whose edges (shown in blue) are all the segments that stay inside the polygon and connect two such vertices (and the start and finish points). Then a standard shortest path algorithm yields the desired path. You can drag the start and finish points to new locations.



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


The algorithm presented here is relatively simple. A more sophisticated algorithm that is theoretically faster is called the funnel algorithm (see [1, 2]).
[1] B. Chazelle, "A Theorem on Polygon Cutting with Applications," in 23rd Annual Symposium on Foundations of Computer Science, 1982, pp. 339–349.
[2] D. T. Lee and F. P. Preparata, "Euclidean Shortest Paths in the Presence of Rectilinear Barriers," Networks, 14(3), 1984 pp. 393–410.
    • 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.