Rasterizing a 2D polygon

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

    • Triangulate your polygon
    • Raster each of the triangles (if you are using a GPU then it can do it for you instead, it's a primitive operation of GPUs)
      • If the triangle doesn't have a segment that is parallel to the x axis, then break it into two triangles with a line that is parallel to the x axis and goes through it's point with the median-y
      • Now the remaining task is to draw a triangle which has a segment that is parallel to the x axis. Such a triangle has a left-side segment and a right-side segment
      • Iterate the triangle's scan-lines (min-y to max-y). For each y calculate the left and right segments' points in that scanlines. Fill the scanline segment these two points (a simple memset).

    Complexity is O(Area in pixels)

提交回复
热议问题