Have been scatching my head about this – and I reckon it’s simple but my geometry/algebra is pretty rubbish, and I can’t remember how to do this stuff from my school days!
EDITED:
I have a list of coordinates with people stood by them – I need an algorithm to order people from top left to bottom right in a list (array), and the second criteria demands that coordinates that are closer towards the top left origin take prescendance over all others – how would you do this?
The code should show the order as:
- Tom
- Harry
- Bob
- Dave
See diagram below:

From your ordering, it looks like you are putting y position at a higher priority than x position, so something like this would work when comparing two people:
edit for update
This comparison still works with your new criteria. Y position is still has precedence over the X position. If the Y values are equal, the point closest to the top left corner would be the one with the smaller X value. If you want to make your object a comparator, implementing this as your comparator function would allow you to do ArrayList.sort() where negative means the first person is before the second: