Bresenham lines w/o diagonal movement

后端 未结 3 1007
遥遥无期
遥遥无期 2020-12-22 01:41

Is there a modified Bresenham algorithm, where the step from one pixel to the next one isn\'t allowed to be diagonally, just horizontally or vertically? Or any other algorit

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 02:45

    Should be a trivial modification - let's say you're in the quadrant I - i.e. going up and to the right. Instead of doing a diagonal, do an up... and then a right.

    Instead of:

      for x from x0 to x1
                 plot(x,y)
                 error := error + deltaerr
                 if error ≥ 0.5 then
                     y := y + 1
                     error := error - 1.0
    

    Something like this:

    for x from x0 to x1
             plot(x,y)
             error := error + deltaerr
             if error ≥ 0.5 then
                 y := y + 1
                 plot(x,y)
                 error := error - 1.0
    

提交回复
热议问题