Rasterizing a 2D polygon

后端 未结 4 1384
予麋鹿
予麋鹿 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:16

    For a robust implimentation of the "even-odd rule"

    See Darel Rex Finley's Efficient Polygon Fill, or Blender's version of it.

    This is an odd/even filling method which supports self intersecting lines, without needing complex code to detect such situations, and doesn't depend on winding (the polygon can be reversed and yield the same results).


    Update, I made an optimized version of Darel Rex's method that avoids looping over all coordinates for each y-pixel.

    Stand alone implementations:

    • C99.
    • Rust (with tests).

    While speedup will likely be exponential, From a quick test, its around 7.5x faster (11x when removing round call), using an arbitrary hand drawn scribble over a 2540x1600 region, YMMV.

提交回复
热议问题