布雷森纳姆线无对角线运动
问题内容:
是否有经过修改的Bresenham算法,不允许从一个像素到下一个像素的对角线(水平或垂直)?还是任何其他算法可以做到这一点?(首选PHP)
Right:
0 0 0 1
0 0 1 1
0 1 1 0
1 1 0 0
Wrong:
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
问题答案:
应该是微不足道的修改-假设您位于I象限-即向上和向右移动。而不是做一个对角线,而是做一个向上…然后是一个右。
代替:
for x from x0 to x1
plot(x,y)
error := error + deltaerr
if error ≥ 0.5 then
y := y + 1
error := error - 1.0
像这样:
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