如何找到两点之间的距离? [英] How do I find the distance between two points?

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

问题描述

假设我有x1,y1,还有x2,y2.

Let's say I have x1, y1 and also x2, y2.

如何找到它们之间的距离? 这是一个简单的数学函数,但是在线上有此代码段吗?

How can I find the distance between them? It's a simple math function, but is there a snippet of this online?

推荐答案

dist = sqrt( (x2 - x1)**2 + (y2 - y1)**2 )

正如其他人指出的那样,您也可以使用等效的内置 math.hypot() :

As others have pointed out, you can also use the equivalent built-in math.hypot():

dist = math.hypot(x2 - x1, y2 - y1)

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

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