Menu

Offset polygon - python

2013-06-21
2013-06-22
  • Kene Meniru

    Kene Meniru - 2013-06-21

    I apologise for this, perhaps, obvious question.

    I am trying to use the python version of clipper. I know there is another "compiled" python version. Perhaps after I understand it more I will used that version (there are fewer docs for it). Also, I just need the offset feature.

    I have a list of coordinates in the form [(x1, y1), (x2, y2), ...] which describe the corners of a polygon. I can change the structure of my coordinates if necessary but there is only one polygon at a time. The corners may be clockwise or anti-clockwise and may also be in the form:

    +----+                    +----------+
    |    |                     \        /
    |    +---------+            +      +
    |              |   or      /        \
    +--------------+          +----------+
    

    Can clipper offset these polygons and can you provide an example of the actual code used in testing this with the python version?

    Example: Offset the following polygon inwards by 0.5
    [(1,1),(3,3), (2,8), (4,8), (4,5), (8,5), (7,3), (8,1)]
    

    Thanks.

     

    Last edit: Kene Meniru 2013-06-21
  • Angus Johnson

    Angus Johnson - 2013-06-22
    subj = []
    s = [Point(10,10),Point(30,30), Point(20,80), 
          Point(40,80), Point(40,50), Point(80,50), Point(70,30), Point(80,10)]
    subj.append(s)
    clip = OffsetPolygons(subj, -2.0)
    # clip[0] contains the solution
    

    Edit: I've scaled up your coordinates because your offsetting delta was too big and so was returning an empty result.

     

    Last edit: Angus Johnson 2013-06-22
MongoDB Logo MongoDB