计算两个 x/y 坐标之间的距离? [英] Calculate distance between two x/y coordinates?
本文介绍了计算两个 x/y 坐标之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想计算 a 圆环.所以,这是一个正常的网格,它的角和边是连接的".例如,在 500x500 的网格上,(499, 499) 处的点与 (0, 0) 相邻,例如(0,0) 和 (0,495) 应该是 5.
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 '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.
有什么好的数学计算方法吗?
推荐答案
我猜你是在圆环的二维表面上寻找欧几里得距离.
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)
其中 w
和 h
分别是网格的宽度 (x) 和高度 (y).
where w
and h
are the width (x) and height (y) of the grid, respectively.
这篇关于计算两个 x/y 坐标之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文