Geometry

Shortest Path by Reflection

Given a line and two points on the same side, find the shortest path that touches the line. Reflecting one point across the line turns the problem into a straight segment — drag the contact point and watch the total distance change.

6 minLevel 2/3The interactive stage stays ad-free.
AP + PB481.6Minimum475.1Extra6.6
ABB′P

Because PB = PB′ (mirror), AP + PB = AP + PB′, which is shortest when A, P, B′ lie on one straight line. Optimal P is at x ≈ 361, distance 475.1.

Drag the slider (or point P) to move the contact point. The amber path A→P→B is what the ant walks; the green dashed line is the unfolded straight route through B′. The minimum happens exactly where they align.

What you are seeing

1

Reflect point B across the line to B′. For any contact point P on the line, PB = PB′, so AP + PB = AP + PB′.

2

AP + PB′ is shortest when A, P, B′ are collinear — a straight line. That P is the answer.

3

Drag P away from the optimal point and the total distance only grows.

Why it matters

This reflection trick (Heron’s problem) is the foundation of many shortest-path and optics results, including the law of reflection: light takes the shortest path.

Complexity & details

Finding the optimum is O(1); the visualization samples positions live.

Frequently asked questions

Why reflect instead of measuring directly?+

Reflection converts a two-segment path with a constraint into one straight line, which is trivially the shortest.