Precise subpixel line drawing algorithm (rasterization algorithm)

前端 未结 2 953
北荒
北荒 2020-11-27 06:37

I need an algorithm which can be (a bit) slower than the Bresenham line drawing algorithm but has to be a lot more exact. With \'exact\' I mean: every touched pixel should b

2条回答
  •  再見小時候
    2020-11-27 06:47

    If your line is thin and pixels are rectangular (square):

    enter image description here

    then consider using of voxel grid traversal algorithms, for example, see article "Fast Voxel Traversal Algorithm..." by Woo and Amanatides.

    Practical implementation (in grid traversal section)

    Answer to comment:
    Proper initialization for X-coordinate variables (the same for Y)

      DX = X2 - X1
      tDeltaX = GridCellWidth / DX
      tMaxX = tDeltaX * (1.0 - Frac(X1 / GridCellWidth)) 
      //Frac if fractional part of float, for example, Frac(1.3) = 0.3
    

    example in my answer here

提交回复
热议问题