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

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

问题描述

我正在使用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天全站免登陆