Python Sympy的Line.distance()方法
在Sympy中,函数distance()是用来寻找指定直线和指定点之间的最短距离。
语法: Line.distance(other)
参数:
other: a point
返回: 线与点之间的最短距离。
Raises: 如果`other’不是一个点,就会产生NotImplementedError。
示例 #1:
# import sympy and Point, Line
from sympy import Point, Line
p1, p2 = Point(0, 0), Point(1, 1)
s = Line(p1, p2)
# using distance() method
shortestDistance = s.distance(Point(-1, 1))
print(shortestDistance)
输出:
sqrt(2)
示例 #2:
# import sympy and Point, Line
from sympy import Point, Line
p1, p2 = Point(0, 0, 0), Point(1, 1, 1)
s = Line(p1, p2)
# using distance() method
shortestDistance = s.distance(Point(-1, 1, 1))
print(shortestDistance)
输出:
2*sqrt(6)/3