Home > OS >  Is there a function to convert coordinates to a list of coordinates creating a circular polygon?
Is there a function to convert coordinates to a list of coordinates creating a circular polygon?

Time:05-30

Example code:

def circle_to_polygon(coordinates, radius, edge_count):
    list = [[1,2],[3,4],[5,6],[7,8],[9,10]]
    return list

Basically I need to create a polygon with a specific radius around a set of coordinates

CodePudding user response:

Shapely - https://shapely.readthedocs.io/en/stable/project.html ?
You could create a point, add a buffer with a radius, take its exterior, control the edge count with simplification or buffer parameters, if needed, and get a list of coordinates.

from shapely.geometry import Point
list(Point(5,5).buffer(1).exterior.simplify(0.05).coords)
[(6.0, 5.0),
 (5.923879532511287, 4.61731656763491),
 (5.707106781186548, 4.292893218813452),
 (5.38268343236509, 4.076120467488713),
 (5.0, 4.0),
 (4.61731656763491, 4.076120467488713),
 (4.292893218813452, 4.292893218813452),
 (4.076120467488713, 4.61731656763491),
 (4.0, 5.0),
 (4.076120467488713, 5.38268343236509),
 (4.292893218813452, 5.707106781186548),
 (4.6173165676349095, 5.923879532511286),
 (5.0, 6.0),
 (5.38268343236509, 5.923879532511287),
 (5.707106781186547, 5.707106781186548),
 (5.923879532511286, 5.3826834323650905),
 (6.0, 5.0)]
  • Related