我创建了一个“Point”类,我想计算给定点和线之间的最短距离(以其他2个点为特征),所有点都是已知的。 我试图用这个公式:| Ax + By + C |/sqrt(A^2 + B^2),但我搞砸了,由于分钟(主要是因为数学公式:()主要是因为:()...Python 3.5.2:从一个点到一条线的距离
我也发现一些网站,人们也问过这个问题,但无论是不是为Python或它是在3D系统没有2D ...
下面是我的课:
class Point:
def __init__(self,initx,inity):
self.x = initx
self.y = inity
def getX(self):
return self.x
def getY(self):
return self.y
def __str__(self):
return "x=" + str(self.x) + ", y=" + str(self.y)
def distance_from_point(self,the_other_point):
dx = the_other_point.getX() - self.x
dy = the_other_point.getY() - self.y
def slope(self,other_point):
if self.x - other_point.getX() == 0 :
return 0
else:
panta = (self.y - other_point.getY())/ (self.x - other_point.getX())
return panta
有人可以帮我写一个单独的函数或方法,做我想要的吗?我试了2个小时,我想不出来...
你的意思是指与这两点相交的无限线,还是延伸在它们之间但不再延伸的线? – Basic
我投票结束这个问题作为题外话,因为它不是一个与编程有关的问题。尝试http://math.stackexchange.com –
@EliKorvigo:哟,我也发现了数学公式,但问题是将它转换成python。此外,任何想要计算三角形面积和任何四边形面积的人(通过将其分成两个三角形) - 我接下来要做的 - 都需要这个。 – ROBlackSnail