當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Sympy Line.distance()用法及代碼示例

在Sympy中,該函數distance()用於查找給定線與給定點之間的最短距離。
用法: Line.distance(other)

參數:  
other: a point

返回: 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


相關用法


注:本文由純淨天空篩選整理自ravikishor大神的英文原創作品 Python | Sympy Line.distance() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。