Search Ctrl K
Home / Tools
THE FEUTEX TOOLKIT

Nearest Point on a Line Segment

Find the nearest point on a finite line segment, including endpoint cases.

Geometry workspace● Runs in your browser
01 Your input
02 Your result
View or copy raw result data
FormulaParameter = max(0,min(1,((x-ax)*(bx-ax)+(y-ay)*(by-ay))/((bx-ax)**2+(by-ay)**2))); Nearest X = ax+(max(0,min(1,((x-ax)*(bx-ax)+(y-ay)*(by-ay))/((bx-ax)**2+(by-ay)**2))))*(bx-ax); Nearest Y = ay+(max(0,min(1,((x-ax)*(bx-ax)+(y-ay)*(by-ay))/((bx-ax)**2+(by-ay)**2))))*(by-ay); Distance = hypot(x-ax-(max(0,min(1,((x-ax)*(bx-ax)+(y-ay)*(by-ay))/((bx-ax)**2+(by-ay)**2))))*(bx-ax),y-ay-(max(0,min(1,((x-ax)*(bx-ax)+(y-ay)*(by-ay))/((bx-ax)**2+(by-ay)**2))))*(by-ay))
Sources and model references

How to use this tool

  1. Enter the labeled inputs using consistent units.
  2. Check the stated assumptions and calculate.
  3. Review each output and compare another input scenario.

Try this example

{
  "ax": 0,
  "ay": 0,
  "bx": 4,
  "by": 0,
  "x": 6,
  "y": 3
}

Accuracy and scope

Projection is clamped to the finite segment; parameter 0 or 1 selects an endpoint. Finite floating-point arithmetic; results can lose precision near singular or extreme inputs.

Is my data uploaded?

This tool runs locally in your browser. Input and output are not sent to a processing server. Copy or download your result before leaving the page.