Get the top-left most point from random points

569 Views Asked by At

For each word in the picture shown below, there is a point that represents the top-left point $(x, y)$ of the rectangle.

How would you find which point is at the most top-left of the page given a random set of points?

In other words, how do you sort a random set of points like this to create the correct English sentence order?

Thanks.

enter image description here

1

There are 1 best solutions below

0
On

A simple way is to find the corner that minimizes $x+my$ (assuming a top-down $y$ axis), where $m$ is a well-chosen slope parameter. The green line is the locus of $x+my=\text{Cst}$, it must intersect a single box.

enter image description here