Python – Sympy Polygon.distance() method
Last Updated :
01 Aug, 2020
In Sympy, the function Polygon.distance() is used to return the shortest distance between the given polygon and o. If o is a point, then given polygon does not need to be convex. But If o is another polygon then, the given polygon and o must be convex.
Syntax: Polygon.distance(o)
Parameters:
o:Point or Polygon
Returns: the shortest distance between the given polygon and o.
Example #1:
Python3
from sympy import Point, Polygon
p1, p2, p3, p4 = map (Point, [( 0 , 2 ), ( 0 , 0 ), ( 1 , 0 ), ( 1 , 2 )])
poly = Polygon(p1, p2, p3, p4)
shortestDistance = poly.distance(Point( 3 , 5 ))
print (shortestDistance)
|
Output:
sqrt(13)
Example #2:
Python3
from sympy import Point, Polygon, RegularPolygon
p1, p2 = map (Point, [( 0 , 0 ), ( 7 , 5 )])
poly = Polygon( * RegularPolygon(p1, 1 , 3 ).vertices)
shortestDistance = poly.distance(p2)
print (shortestDistance)
|
Output:
sqrt(61)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...