1

I have a collection of polygons, created with scipy.spatial.Voronoi (specifically, a subset of the Voronoi regions), which I'd like to plot with matplotlib. However, it seems like there are some constraints on the vertex order of the matplotlib polygons, since some of the polygons end up with the fill on the outside of the polygon rather than the inside. In these cases, reversing the order the vertices are specified seems to fix the problem, so it seems to me like a winding issue (even if the docs don't mention anything like this).

However, since some polygons are in the right order and some are in the wrong order, I can't just reverse all the vertex lists, so is there a way I can detect the incorrectly wound lists and fix only those or alternatively a way to get matplotlib to do the equivalent thing automatically?

arnsholt
  • 851
  • 7
  • 17
  • 1
    I suppose the polygons are convex? Then checking if their points wind counterclockwise around a center point would tell you if they need to be reversed or not. – ImportanceOfBeingErnest Nov 19 '19 at 15:40

1 Answers1

0

ImportanceOfBeingErnest's comment put me on the right track, which in turn led me to How to determine if a list of polygon points are in clockwise order?. Basically, we find the bottom-rightmost point in the polygon P, the point A before P, and the point B after P. The sign of the cross product AP x PB gives the winding: positive in case of CCW winding and negative for CW winding.

arnsholt
  • 851
  • 7
  • 17