Is there a mathematical equation for making a line from a set of unordered points?

76 Views Asked by At

I'm currently working with WGS84 coordinates, like so:

Points example

Those points are unordered and have no co-relation between them besides being distributed on a line that can have different angles(Streets have different shapes).

I'm trying to make a line from those set of points, like so: Line from points

The line itself has no special conditions apart from retaining the same shape that can be observed from such points and having the same length. As a human, drawing given line is an easy task, but translating those instructions to a computer algorithm, so far, has been proven kinda difficult.

The first solution i came with is using a Voronoi Diagram to find the farthest-points, that are the ones where the area is the largest given the bounding box(World map). After finding given points, i use nearest neighbor search, iterating over each point to start drawing a line. It works, but recently i found out about Linear least squares, that do exactly what i need, however, the result is a line equation that goes to infinity.

I tried also ordering the values by latitude and longitude, and so goes on, but i ended up in the same problems of this question.

Is there any equation that does that? Create a line from given set of points respecting its limits and shape?

1

There are 1 best solutions below

4
On

Basic linear regression:

enter image description here

Terminate the line wherever you wish.