距离2点 [英] Distance between 2 points

查看:132
本文介绍了距离2点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算两点之间的粗略距离,为了减少计算开销,我使用下面的公式:(b1 b1 b1 b1)(x1,y1)& amp; amp; ; (x2,y2)

  Dist = Mod(x1  -  x2)+ Mod(y1  -  y2)
code>

其中Mod是Modulus运算符Mod(x)= | X |。



我想知道,如果我错过了一些东西......

解决方案

/ p>

如果这就是你想要的,那么你没有错过任何东西



如果你想要直线距离使用毕达哥拉斯定理。这是sqrt((x1 - x2)^ 2 +(y1 - y2)^ 2)

I want to calculate the rough distance between two points, and to reduce the computation overhead, I am using the following formula

Distance between (x1, y1) & (x2, y2)

Dist = Mod (x1 - x2) + Mod (y1 - y2)

Where Mod is the Modulus operator Mod(x) = |X|.

This seems to be working.

I want to know, if I have missed out something ...

解决方案

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

If you want the straight line distance use the pythagorean theorem. This is sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2)

这篇关于距离2点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆