Rasterizing a 2D polygon

后端 未结 4 1380
予麋鹿
予麋鹿 2020-12-09 21:54

I need to create a binary bitmap from a closed 2D polygon represented as a list of points. Could you please point me to efficient and sufficiently simple algorithms to do th

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 22:06

    You can check out the polygon fill routine in Pygame. Look at the draw_fillpoly function.

    The algorithm is pretty simple. It finds all the positions that each segment intersects along the Y axis. These intersections are sorted, and then horizontally fills each pair of intersections.

    This will handle complex and intersecting shapes, but obviously you could crush this algorithm with large amounts of segments.

提交回复
热议问题