Calculate distance between two x/y coordinates?

前端 未结 4 1138
面向向阳花
面向向阳花 2021-02-05 05:18

I would like to calculate the distance between two x/y coordinates on the surface of a torus. So, this is a normal grid that has the property that its corners and sides are \'co

4条回答
  •  滥情空心
    2021-02-05 05:59

    So you are looking for the Euclidean distance on the two-dimensional surface of a torus, I gather.

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

    where w and h are the width (x) and height (y) of the grid, respectively.

提交回复
热议问题