best fit, minimizing point-to-line error, not y error

I have a set of [x, y] points that trend in a path, and I would like to find piece-wise equations to model the entire path.

What I am thinking of doing is:

1) Order the points, based on proximity to one another, so that I have an ordered set [x0, y0] ... [xn, yn]

2) Find contiguous subsets of points that can be modeled by the equation $\displaystyle ax + by + c = 0$. I would start a new piecewise set when the average deviation from the line becomes too high.

I might end up with:

For [x0, y0] through [x5, y5]: $\displaystyle ax + by + c = 0$

For [x6, y6] through [x9, y9]:$\displaystyle a'x + b'y + c' = 0$

For [x10, y10] through [x12, y12]: $\displaystyle a''x + b''y + c'' = 0$

... More piecewise functions until I reach [xn, yn]

Anyway, I'm not sure how to use least squares or something like it to solve for a, b, and c. As I've seen it done, least squares just solves for$\displaystyle f(x) = y = ax + b$, but I want to be able to have lines that are potentially vertical and never intersect the y axis. I don't want to minimize the y-distance error. I want to minimize the point-to-line distance.

Thanks for any ideas