# Python – Sympy Polygon.distance() method

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

 `# import sympy import Point, Polygon ` `from` `sympy ``import` `Point, Polygon ` ` `  `# creating points using Point() ` `p1, p2, p3, p4 ``=` `map``(Point, [(``0``, ``2``), (``0``, ``0``), (``1``, ``0``), (``1``, ``2``)]) ` ` `  `# creating polygon using Polygon() ` `poly ``=` `Polygon(p1, p2, p3, p4) ` ` `  `# using distance() ` `shortestDistance ``=` `poly.distance(Point(``3``, ``5``)) ` ` `  `print``(shortestDistance)`

Output:

`sqrt(13)`

Example #2:

## Python3

 `# import sympy import Point, Polygon, RegularPolygon ` `from` `sympy ``import` `Point, Polygon, RegularPolygon ` ` `  `# creating points using Point() ` `p1, p2 ``=` `map``(Point, [(``0``, ``0``), (``7``, ``5``)]) ` ` `  `# creating polygon using Polygon() and RegularPolygon() ` `poly ``=` `Polygon(``*``RegularPolygon(p1, ``1``, ``3``).vertices) ` ` `  `# using distance() ` `shortestDistance ``=` `poly.distance(p2) ` ` `  `print``(shortestDistance)`

Output:

`sqrt(61)`
My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.