粗略计算2点之间的距离

编程入门 行业动态 更新时间:2024-10-28 01:18:50
本文介绍了粗略计算2点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想计算两点之间的粗略(近似)距离,以减少计算开销。

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点之间的距离

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

发布评论

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

>www.elefans.com

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