# Can someone tell me what “min” means in this context?

I am attempting to write a function (programming, not mathematics) which calculates the shortest distance between two points on a toroid. I got the following formula from StackOverflow, but I don't recognize the min portion. Can someone explain that to me, please?

sqrt(min(|x1 - x2|, w - |x1 - x2|)^2 + min(|y1 - y2|, h - |y1-y2|)^2)

-

## 1 Answer

As explained in the question you reference, this toroid is created by identifying the sides of a rectangle w units wide in the x direction and h units high in the y direction. So assume you have two points (x1,y) and (x2,y), at the same height and let x2>x1. To get from (x2,y) to (x1,y) you can either go left a distance x2-x1, or you can go right (off the edge) and come around a distance of (w-x2)+x1. The min just picks the smaller of these. Similarly in y.

-
Thanks a lot. I read through the other answers and figured that out, but I appreciate your answer. –  Caleb Thompson Dec 10 '10 at 18:58