How this calculation works
The straight segment between two points is shortest in an unconstrained plane, but a concave polygon can force that segment outside the allowed region. A shortest path within a simple polygon is a polyline whose bends can occur at visible boundary vertices. This calculator builds that visibility graph from the polygon and the two endpoints, checks that each candidate segment stays within the closed polygon, and runs a weighted shortest-path search. It returns the route coordinates and total Euclidean length, rather than asking the user to supply a graph that already encodes the geometric restrictions.
Build visible endpoint/vertex pairs with Euclidean edge lengths, then minimize the sum of edge lengths from start to end.A worked example
In the L-shaped polygon (0,0),(4,0),(4,1),(1,1),(1,4),(0,4), start at (3,0.5) and end at (0.5,3). Their direct segment crosses the excluded upper-right region. The shortest valid route bends at the concave corner (1,1). Each leg has length sqrt(4.25), so the total is sqrt(17), approximately 4.123106. The corner belongs to the closed boundary, so touching it is permitted; a required clearance from walls would define a different route problem.
Good to know
One simple polygon boundary without holes, 3–60 bounded decimal vertices, with endpoints inside or on the boundary. Closed-boundary travel and endpoint coincidence are supported. Segment containment uses robust orientation with numeric subdivision locations; distances and shortest-path comparisons are numerical. No curved walls, holes, multiple obstacles, clearance radius, terrain-weighted costs, geographic routes or 3D navigation. This mathematical path is not a safety-certified motion plan.
Reference: CGAL — visibility within simple polygon environments (opens in a new tab) ↗
Visibility must certify the whole segment, not just its midpoint
A segment can leave a concave polygon and reenter even when its midpoint lies inside. This solver rejects proper crossings of boundary edges and splits candidate segments at collinear boundary vertices before checking every interval. That handles a segment passing through a reflex corner or along a boundary edge without treating the full line as automatically visible. Polygon validation happens first so visibility has a single simple-region meaning.
The graph includes both endpoints and all boundary vertices. A valid Euclidean shortest path can be straightened between consecutive bends; any necessary bend lies at a boundary corner. Complete visibility edges therefore contain a shortest route for the supported simple polygon. Edge weights are actual coordinate distances, and the graph search minimizes their sum. Minimizing the number of bends would be another objective and can return a longer route.
The allowed region and boundary convention define the answer
This page treats the polygon as a closed region, so a path may touch corners or follow boundary segments. A robot, person or object with nonzero radius needs a clearance-adjusted free space; reusing the point route without that adjustment can cause a collision. Likewise, a hole cannot be represented by jumping from one ring into another in a single coordinate list. The supported region is exactly one simple boundary with no holes.
Coordinates are Cartesian and share one unit. Latitude/longitude entered as if they were planar metres would not give geographic shortest distances. The Shortest path calculator for a weighted graph edge list optimizes a network supplied by the user; it does not derive visibility from polygon geometry. Here that derivation is the main operation, and the output route is checked within the supplied region rather than inferred from a visual drawing alone.
A few questions, answered
Can the route run along a polygon edge?
Yes. The allowed polygon is closed, so its boundary is part of the region. Required clearance or a forbidden-boundary rule would change the problem.
Does the route minimize the number of turns?
No. It minimizes total Euclidean length. A path with more bends can be shorter than another path with fewer bends.