1

I need to create an image containing a convex polygon, given only the vertices of the polygon. Therefore, I need to find which of the pixels in the image would lie inside the polygon, and colour them differently.

I thought about casting rays from each pixel to count the line intersections and deduce whether the pixel is inside a polygon or not, but this would take a long time to run for hundreds of pixels.

How can I do this more efficiently? I am using Python, with PIL to create the image.

prosoitos
  • 6,679
  • 5
  • 27
  • 41
Epic0Tom
  • 11
  • 1
  • You can find the min and max of the x and y of each vertex to bound the problem to a finite set of pixels to test. Then, I wonder if this will tell you how to test each pixel: https://stackoverflow.com/questions/217578/how-can-i-determine-whether-a-2d-point-is-within-a-polygon – CryptoFool Sep 26 '20 at 17:58
  • 2
    With [`ImageDraw.polygon(xy, fill=None, outline=None)`](https://pillow.readthedocs.io/en/stable/reference/ImageDraw.html) you can specify the border color `outline` and the fill color `fill`. – Michael Szczesny Sep 26 '20 at 18:38

0 Answers0