Calculator: Point to segment distance

Enter the labelled inputs to calculate: Distance; Value Qx; Value Qy; Coefficient t.

Distance
1.414213562
Value Qx
2
Value Qy
0
Coefficient t
1

How the calculation works

t=clamp((P−A)·(B−A)/‖B−A‖²,0,1); Q=A+t(B−A)

Separate list values with spaces or semicolons. Matrices are row-major. Coordinates share one unit; angles are degrees. Quaternion order is w,x,y,z and rotation normalizes the quaternion. Parallel lines and singular inverses are rejected.

Values must satisfy the formula’s domain. Nonzero results too small or too large for reliable representation are rejected.

Frequently asked questions

How is the result calculated?

t=clamp((P−A)·(B−A)/‖B−A‖²,0,1); Q=A+t(B−A)

What assumptions apply?

Separate list values with spaces or semicolons. Matrices are row-major. Coordinates share one unit; angles are degrees. Quaternion order is w,x,y,z and rotation normalizes the quaternion. Parallel lines and singular inverses are rejected.

How precise are the displayed results?

Numerical results show up to ten significant digits. Rounding does not improve the accuracy of the input measurements or the model. Values must satisfy the formula’s domain. Nonzero results too small or too large for reliable representation are rejected.

How we verified this calculator

The calculator is checked against 3 reference cases computed independently of its code. Last passed: .

# Inputs Expected result
1
Values (spaces or semicolons; decimal point) P = 3 4
Values (spaces or semicolons; decimal point) A = 0 0
Values (spaces or semicolons; decimal point) B = 6 0
Distance: 4
Value Qx: 3
Value Qy: 0
Coefficient t: 0.5
2
Values (spaces or semicolons; decimal point) P = -2 1
Values (spaces or semicolons; decimal point) A = 0 0
Values (spaces or semicolons; decimal point) B = 4 3
Distance: 2.236067977
Value Qx: 0
Value Qy: 0
Coefficient t: 0
3
Values (spaces or semicolons; decimal point) P = 5 5
Values (spaces or semicolons; decimal point) A = 1 1
Values (spaces or semicolons; decimal point) B = 2 3
Distance: 3.605551275
Value Qx: 2
Value Qy: 3
Coefficient t: 1

How we test our calculators →

Also try:

Back to category →