# Sort list of Vector3s by 2 distances

Is it possible to sort a List<> using 2 different distances. This is hard to explain but, for example: A list of Vector3s is ordered in ascending order from the closest to object A but also the furthest from object b. I know my explanation is terrible but if you get it, is this possible and how should I do it?

If you don’t depend on total precision in distance get the point in the middle of the two and sort by distance to it.

Otherwise, lets say you have two distance points from the oposite side of all of your elements, since they are 3 dimensional you can take 4-5 of some objects next to you and 2 objects that will be distance points, write down their order by distance from the first object, now go from one direction of that order and compare the distances, from the first swap you make the list doesn’t obey the first criteria anymore, so you can’t get the list to have 100% of both conditions unless you:

1. have complementary criterias that exclude one another, like sorting by (x and y, z), (x and z, y) or (y and z, x).
2. have something all elements have the same in both conditions! For example, sorting a list of people by their last name first and then their first name means that you sort by last name, and then you sort people that have the same last name by their name. Similarly you could see if there are objects equally distanced from the first object and sort those that have the same distance by the second distance. Since that is not a very common thing to happen in 3d space, to have perfectly distanced objects from a point (only objects on a sphere or at the very same location) you could make an offset value that would group objects from almost the same distance and inside those groups sort by distance from another objects. So, sort by the first order, then separate the elements that are clustered that fit close to each other by that first distance, then sort those separate groups by another distance this time ignoring the first criteria causing them to almost fit the first and partially fit the second condition.