+3  A: 

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:

if (a.y > b.y)
// a is before b
else if (a.x < b.x)
// a is before b
else
// b is before a

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:

public int compareTo(person a, person b) {
    if (a.y == b.y)
       return a.x-b.x
    else
       return b.y-a.y
}

//compareTo(Tom, Harry) == -50 (tom is before harry)
//compareTo(Tom, Bob) == -25 (tom is before bob)
//compareTo(Dave, Bob) == 30 (dave is after bob)
yx
Instead of "bigger", you should say "before". The built-in Java sorting routines sort in ascending order, so to say "bigger" is confusing. But at least you got the right comparison in the y-dimension, so +1.
erickson
fixed, thanks (15 chars)
yx
+1  A: 

If you know max order of magnitude of X, sort by (for your given example) 100 * (100 - Y) + X.

John Pirie
Or rather 100 * X - Y based on his chosen coordinate system ;)
jerryjvl
Erk... X - 100 * Y even... brain freeze :)
jerryjvl
You're right, but I think both of your formulas are incorrect; edited.
John Pirie
The second one works fine as long as negative values of the objective function are allowable... the only difference in your correction is that you add a constant 10000, which makes all values positive.
jerryjvl
+2  A: 

Order them based on their distance from the top-left corner of your 2D-Space, in this case (0, 100).

EDIT:

Obviously this will mean that you will have cases where 2 people are equidistant from the top left corner, and yet they are nowhere near each other.

In this case, you need to specify how you want such people to be ordered. If you want to pick people who are higher up, you can order by y-coord first. Similarly you can choose some other criterion.

All other sorting algorithms will have the same problem, of what to do when 2 items have the same sort key. By definition then, they are considered identical until you come up with a secondary sorting criterion.

sykora
this would not work - because if you had someone stood at (0,0) and someone at (100,100) they would be equidistant from (0,100) - thanks though
Vidar
this is a good start. if they are equidistant, then they are equivalent, i.e. "Pear" and "Pear" in a list or you need a secondary criteria
You want to order them from top-left to bottom-right. In the absence of further ordering criteria, someone at (0, 0) _is_ in the same boat as someone at (100, 100). If you want the algorithm to prefer one ordering over another, you need to specify how it should behave.
sykora
Well...yes...thats "exactly" the problem - if two people are equidistant the algorithm fails, as you cant just rely on JUST measuring distance from (0,100) - you need a smarter algorithm to take care of that eventuality.
Vidar
I don't think it fails, they are just equivalent. You can sort a list of People by name if two People have the same name.
@Vidar The problem is you didn't define your problem well enough. Top-left to bottom-right is too broad a definition.You should specify how you want the algorithm to behave for some one at (0,0) and (100, 0) so you will get the answer you are looking for.
freespace
@Wilmus - forget the names - they are irrelevant, they were just used to help explain things.
Vidar
I think it fails by my interpretation of top-left to bottom-right. Think of a raster sweeping across the square. 100,100 comes before 0,99 to me.
banjollity
And sorting by y-then-x fails by my interpretation - I would expect 2,0 to come before 1,100 - but it really depends on what exactly Vidar means with "top-left to bottom-right"
Michael Borgwardt
@freespace - I think you are right despite my earlier comments - I need to be more explicit on my problem
Vidar
A: 

The comparator looks like this:

int d = o2.y - o1.y;
if (d == 0)
    d = o1.x - o2.x;
return d;

This will first sort by Y, then by X (for all objects which have the same Y).

[EDIT] Fixed Y sort order.

Aaron Digulla
This sorts the wrong direction in the y dimension (Tom.y - Dave.y = +15, so they would be swapped).
erickson
A: 

May be you could look into the Haversine formula which is used in navigation to calculate proximity from two points. However, that mostly applies to points on a sphere. http://en.wikipedia.org/wiki/Haversine_formula

Emmanuel
+1  A: 

I'd say:

orderValue = x+(100-y)

Then sort based on the smallest orderValue being the "closest" (according to distance projected on to the line y=100-x) to the top-left.

fd