距离2点

编程入门 行业动态 更新时间:2024-10-27 17:16:44
本文介绍了距离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点

本文发布于:2023-10-27 22:33:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534743.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:距离

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!