quality:correction
In two dimensions

In the two-dimensional case, first, represent line i as a point p on the line and a unit normal vector n̂, perpendicular to that line. That is, if x and x are points on line 1, then let p = x and let

which is the unit vector along the line, rotated by a right angle.

The distance from a point x to the line (p, n̂) is given by

And so the squared distance from a point x to a line is

The sum of squared distances to many lines is the cost function:

This can be rearranged:

To find the minimum, we differentiate with respect to x and set the result equal to the zero vector:

so

and so