Sorting triangles by hypotenuse length

28 Views Asked by At

I have some points in $xy$ space and I need to sort distances between these points. If I calculate real distance, then I need to perform $\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}$ and this is very time consuming operation. As I understand, I can easily omit square root for sorting purposes. But I want to go further. Can I use $|x_1-x_2| + |y_1 - y_2|$ instead of initial equation for sorting?

1

There are 1 best solutions below

0
On BEST ANSWER

No.

Consider $x_1-x_2=4$, $y_1-y_2=4$ then $(x_1-x_2)^2+(y_1-y_2)^2=32$ and $|x_1-x_2|+|y_1-y_2|=8$. But $x_1-x_2=6$, $y_1-y_2=1$ then $(x_1-x_2)^2+(y_1-y_2)^2=37$ and $|x_1-x_2|+|y_1-y_2|=7$. So this would give the wrong comparison.