title: Calculate distance between two x/y coordinates?
body: <p>I would like to calculate the distance between two x/y coordinates on the surface of <a href="http://en.wikipedia.org/wiki/Torus" rel="noreferrer">a torus</a>. So, this is a normal grid that has the property that its corners and sides are 'connected'. For example, on a grid of 500x500, the point at (499, 499) is adjacent to (0, 0) and the distance between e.g. (0,0) and (0,495) should then be 5.</p>
  
  <p><strong>Is there any good mathematical way of calculating this?</strong></p>