📜  Python| Sympy Line.distance() 方法

📅  最后修改于: 2022-05-13 01:55:45.137000             🧑  作者: Mango

Python| Sympy Line.distance() 方法

在 Sympy 中,函数distance()用于查找给定线和给定点之间的最短距离。
Syntax: Line.distance(other)

Parameter:  
other: a point

Returns: shortest distance between a line and a point

Raises: NotImplementedError is raised if `other` is not a Point

示例 #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