粗略计算2点之间的距离 [英] Rough computation of distance between 2 points
问题描述
我想计算两点之间的粗略(近似)距离,以减少计算开销。
I want to calculate the rough (approximate) distance between two points to reduce the computation overhead.
我使用以下公式计算(x1, y1)& (x2,y2):
I am using the following formula for the distance between (x1, y1) & (x2, y2):
Dist = Mod (x1 - x2) + Mod (y1 - y2)
其中Mod是模数运算符,使得Mod(x)= | X |。
Where Mod is the Modulus operator such that Mod(x) = |X|.
这似乎有效。
我想知道,如果我错过了什么......
I want to know, if I have missed out something ...
推荐答案
只要你得到绝对值(就像你说的那样| X |)并且没有使用模数函数那么这将给你曼哈顿之间的距离两点
As long as you're getting the absolute value (like you stated |X|) and not using the modulus function then that will give you the manhattan distance between the two points
如果这就是你想要的,那你就没有错过任何东西
If that is what you want, then you've not missed anything
如果你想要的话直线距离使用毕达哥拉斯定理。这是sqrt((x1 - x2)^ 2 +(y1 - y2)^ 2)
If you want the straight line distance use the pythagorean theorem. This is sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
这篇关于粗略计算2点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!