点到线的距离(从两点开始) [英] Distance between point and a line (from two points)

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

问题描述

我正在使用 Python+Numpy(也可以使用 Scipy)并且有三个 2D 点

I'm using Python+Numpy (can maybe also use Scipy) and have three 2D points

(P1, P2, P3); 

我试图使 P3 的距离垂直于 P1 和 P2 之间绘制的线.让 P1=(x1,y1), P2=(x2,y2)P3=(x3,y3)

I am trying to get the distance from P3 perpendicular to a line drawn between P1 and P2. Let P1=(x1,y1), P2=(x2,y2) and P3=(x3,y3)

在矢量表示法中,这会很容易,但我对 python/numpy 还很陌生,无法获得任何有效(甚至接近)的东西.

In vector notation this would be pretty easy, but I'm fairly new to python/numpy and can't get anythng that works (or even close).

感谢任何提示,谢谢!

推荐答案

尝试使用 numpy.linalg

d = norm(np.cross(p2-p1, p1-p3))/norm(p2-p1)

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

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