Wu的抗锯齿算法,垂直线
我主要按照 Xiaolin Wu 的算法 实现 Wu 的算法,但是遇到了有点麻烦。具体来说,该算法的这一点包含在 wiki 条目底部的注释中:
如果在例程开始时abs(dx) <绝对值(dy)为真, 那么所有的绘图都应该在 x 和 y 颠倒的情况下完成。
我认为这意味着只需用plot(y, x)反转对plot(x, y)的所有调用,但这样做会导致一些非常特殊的线条(我似乎无法获得屏幕截图,因为每次我尝试,我的 OpenGL 窗口将空白粘贴到 Paint 中)。
以前实施过此操作的人可以给我一些指导吗?我的线条现在看起来有点傻,每个象限只填充了一半。
I've been implementing Wu's algorithm mostly per Xiaolin Wu's algorithm, but have run into a bit of a snag. Specifically, this bit of the algorithm, which is included by a note at the bottom of the wiki entry:
If at the beginning of the routine abs(dx) < abs(dy) is true, then all plotting should be done with x and y reversed.
I thought that this meant just reverse all the calls to plot(x, y) with plot(y, x), but doing so resulted in some very special looking lines (I can't seem to get a screenshot because every time I try, my OpenGL window pastes blank into Paint).
Can anyone who has implemented this before give me a bit of guidance? My lines look a bit silly right now with only half of each quadrant filled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不仅应该将
plot(x,y)
与plot(y,x)
交换,还应该交换输入参数x1<->y1
> 和x2<->y2
。如果您同时执行这两项操作,它将正常工作。后一部分是在文章的代码中完成的,但没有进行绘图坐标的切换。背后的原因是您在
x
范围内逐像素步进。如果您的水平范围小于垂直范围,则可能会产生间隙(例如,一条完全垂直的线将导致它仅产生一个 x 值)。因此,您可以切换输入参数
x
和y
,但同时切换输出坐标系(通过交换x
和y
> 在绘图函数中)。You should not only swap
plot(x,y)
withplot(y,x)
but also exchange the input parametersx1<->y1
andx2<->y2
. If you do both it´ll work correctly. The latter part is done in the code in the article but not the switch of the plot coordinates.Reason behind is that you step pixel by pixel in
x
range. If your horizontal extent is less than vertical it might yield gaps (think e.g. a perfectly vertical line which would result it a single x-value only).Therefore you switch input parameters
x
andy
but at the same time the output coordinate system (by exchangingx
andy
in the plot function).