Closest Intersection of Lines Calculator

Enter equations in standard form with optional positive weights. The worksheet finds the exact point or line that minimizes squared perpendicular distances and diagrams the foot on each input line.

Linear systems

Fit a shared point to conflicting lines

Line measurements

For ax + by = c, enter a, b, c and an optional positive weight. Use one line per row and the same units on both axes. The default weight is 1.

One point minimizes the weighted distances.

Best fit and minimum distance

Fit point (x, y)
(18/25, 24/25)
Weighted RMS distance
0.9797959
Weighted sum of squared distances
72/25
Optimal set
One point

Compare perpendicular distances

Lines and perpendicular distances

Equal x and y scales · ±1.2 around the shown point

Equal-scale map of the input lines and fitOne point minimizes the weighted distances. Equal x and y scales around the shown point (18/25, 24/25). Line 3 has perpendicular distance 1.2 with foot (36/25, 48/25).x offset →y ↑
Selected line Perpendicular distance Shown point
Selected equation
3x + 4y = 12
Perpendicular foot
(36/25, 48/25)
Distance squared
36/25
Distance and weight by line
LineWeightDistanceWeighted loss
110.72324/625
210.96576/625
311.236/25

Export the intersection worksheet

Save exact feet, squared distances, and each line’s contribution to the fit.

View CSV text

How to use this calculator

  1. Enter one standard-form line per row, with coefficients a, b and c and an optional positive weight.
  2. Read the fit point, minimum weighted squared distance and weighted RMS. For parallel inputs, read the full optimal line.
  3. Choose a line to highlight its normal segment, perpendicular foot and squared distance.
  4. Download the exact worksheet CSV to compare residuals and weights outside the calculator.

The Formula

The mathematical logic powering this calculation is:

Write each line as aᵢx + bᵢy = cᵢ with positive weight wᵢ. Its perpendicular distance squared from point p=(x,y) is dᵢ² = (aᵢx + bᵢy − cᵢ)²/(aᵢ² + bᵢ²). The objective is Σ wᵢdᵢ². Multiplying all three coefficients of one equation by the same nonzero constant leaves its contribution unchanged. Use the same physical units on both coordinate axes.

Let nᵢ=(aᵢ,bᵢ) and kᵢ=wᵢ/(aᵢ²+bᵢ²). Form H=Σ kᵢnᵢnᵢᵀ and z=Σ kᵢcᵢnᵢ. The minimizing point solves Hp=z. Any two nonparallel lines give a positive determinant and one unique point. If all lines are parallel, H has rank one and its only positive eigenvalue is its trace Σwᵢ. The nearest-to-origin minimizing point is z/Σwᵢ. The whole optimal line is parallel to the entries and passes through that shown point.

For the perpendicular foot, subtract (nᵢ·p−cᵢ)nᵢ/(aᵢ²+bᵢ²) from p. The report adds the weighted squared distances exactly and takes the square root of their sum divided by total weight for the weighted RMS. The plotted segments use common x and y scales centered at p. The derived best-fit coordinates can be far beyond the entered coefficients when the lines are almost parallel.

Enter two through eight rows of a, b, c and optional weight. Use comma or space separation and signed decimals through ±1,000,000 with at most 12 fractional places. A normal vector must be nonzero and a weight must be positive. Missing weights use 1. Equation results, squared distances and the geometry used for plotting use exact rational arithmetic. Displayed distances and chart positions are rounded.

Worked Example

If you input:

  • Line 1: x = 0
  • Line 2: y = 0
  • Line 3: 3x + 4y = 12
  • Weights: All 1

Result:

The best-fit point is (18/25, 24/25) and the minimum weighted squared distance is 72/25. The diagonal’s perpendicular foot is (36/25, 48/25). Weighted RMS distance is approximately 0.9797959.

Frequently Asked Questions

Why divide by a² + b²?

Dividing by the length of the normal vector squared converts the squared equation residual into squared geometric distance. This makes equivalent rescalings of the same line produce identical results.

What does a weight change?

A line with larger weight contributes more to the sum of squared distances. Use equal weights when no measured priority is available. The entered weights are relative priorities.

Why might the answer be an entire line?

With parallel inputs, motion along the shared line direction leaves every distance unchanged. The calculator reports the whole minimizing line and plots its point nearest the origin.

What if the rows have a common solution?

The minimum is exactly zero. If the line directions vary, this happens at their unique common point. Coincident lines share every point on that line.

Similar Calculators