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

• Mar 3rd 2011, 06:53 PM
evokanivo
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 $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]: $ax + by + c = 0$
For [x6, y6] through [x9, y9]: $a'x + b'y + c' = 0$
For [x10, y10] through [x12, y12]: $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 $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
• Mar 4th 2011, 05:16 AM
Ackbeet