Distance between point and a line (from two points)

后端 未结 8 2344
梦谈多话
梦谈多话 2020-11-28 07:30

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

(P1, P2, P3); 

I am trying to get the distance from P3 perpend

8条回答
  •  渐次进展
    2020-11-28 07:49

    To find distance to line from point if you have slope and intercept you can use formula from wiki https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line Python:

    def distance(point,coef):
        return abs((coef[0]*point[0])-point[1]+coef[1])/math.sqrt((coef[0]*coef[0])+1)
    

    coef is a tuple with slope and intercept

提交回复
热议问题