ArKi
ArKi

Reputation: 701

How do I group points together are in the same curved "row"?

Let's say I have a list of points (x,y) that are correspond to the black dots in the image below, which is a rectangular grid. Here, there are four curved "rows", and eight "columns". enter image description here

How would I group the each row of points together? In other words, in the image below, how I do group together the first row of points circled in blue (let's call this Group 1), and group together the second row of points circled in blue (let's call this Group 2), etc. enter image description here

My initial intuition says to start with the top-left point, and search for the closest point using a distance metric that would penalize the y-distance between two points. However, the problem I run into is that when I reach the last point in the first row, how do I know that the row is "complete", and I shouldn't add the right-most point of the 2nd row to my group of points?

Is there a better approach to this type of problem?

Upvotes: 0

Views: 167

Answers (1)

Piglet
Piglet

Reputation: 28950

That highly depends on how the points are distributed.

For this special case a simple solution would be:

sort points by x

split point list into groups of 4 consecutive points (that's your columns)

sort columns by y

pick the first element of each column and put into row 1

pick the second element of each column and put it into row 2

...

Upvotes: 1

Related Questions