布氏线W / O型对角线运动 [英] Bresenham lines w/o diagonal movement

查看:211
本文介绍了布氏线W / O型对角线运动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有改性Bresenham算法,其中,从一个像素到下一个步骤是不允许是对角线,只是水平或垂直?或者有什么其他的算法,这是否? (PHP preferred)

 右:
0 0 0 1
0 0 1 1
0 1 1 0
1 1 0 0

错误:
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
 

解决方案

应该是一个微不足道的修改 - 假设你在象限I - 即往上走和向右。而不是做一个对角的,做一个了......然后的权利。

相反的:

 从X0到X1 x
             积(X,Y)
             错误:=误差+ deltaerr
             如果错误≥0.5,那么
                 Y:= Y + 1
                 错误:=错误 -  1.0
 

事情是这样的:

 从X0到X1 x
         积(X,Y)
         错误:=误差+ deltaerr
         如果错误≥0.5,那么
             Y:= Y + 1
             积(X,Y)
             错误:=错误 -  1.0
 

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 algorithm which does that? (PHP preferred)

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

解决方案

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

这篇关于布氏线W / O型对角线运动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆