how to find the line with minimum sum of distances to multiple Points?

387 Views Asked by At

I am programming on a little physics simulation right now. The mathematical problem i am facing now, is pretty hard for me, a 17 year old high school student. But since i really need to solve this one, i thought i might just ask if somebody knows something about the problem.

The Problem:

All in 2D.

Given a certain number of points, find a line that approximates these points the closest.

I know this sounds much like a regression line, but a regression line minimizes the y distances from line to points. I want to approximate not in a statistical sense like regression line, but a geometrical sense. I want to minimize the actual right angled shortest distances from points to the line. distances to minimize (red)

The only solution i could think off was to make a function (f(m , h)) that takes the parameters of a line (y = mx + h) and gives the sum of distances squared. But finding a minimum of such a long multivariable function was not possible for me.

Since this seems like basic stuff to me i thought this problem is well documented, but i could not find anything about it. Please redirect me if you know the name of this problem.

Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

This is Orthogonal Distance Regression. If you'd like to, there exists a scipy solution to it