Paths inside a Polygon

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram CDF Player or other Wolfram Language products.

Requires a Wolfram Notebook System

Edit on desktop, mobile and cloud with any Wolfram Language product.

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.

Contributed by: Stan Wagon (April 2012)
Suggested by: Karen Saxe
(Macalester College)
Open content licensed under CC BY-NC-SA



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.

Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.