Bresenham 线算法(厚度)
我想知道是否有人知道基于 Bresenham 线算法或任何类似算法来绘制特定粗细线的算法。
再一想,我一直想知道对于每个 setPixel(x,y) 我只画一个圆圈,例如:
filledCircle(x,y,thickness);对于每个 x,y 但这当然会非常慢。我也尝试过使用字典,但这很快就会填满记忆。检查我要绘制的像素是否具有相同的颜色,但这对于大型画笔来说也不够有效。
也许我可以根据角度画半圆?
任何意见将不胜感激。
谢谢。
I was wondering if anyone knew of any algorithm to draw a line with specific thickness, based on Bresenham's line algorithm or any similar.
On a second thought, I've been wondering about for each setPixel(x,y) I'd just draw a circle, e.g.:
filledCircle(x,y,thickness); for every x,y but that would of course be very slow. I also tried to use dictionary but that would fill the memory in no time. Check the pixels I'm about to draw on if they have the same color, but that's also not efficient enough for large brushes.
Perhaps I could somehow draw half circles depending on the angle?
Any input would be appreciated.
Thanks.
duplicate: how do I create a line of arbitrary thickness using Bresenham?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您实际上无法沿着线画圆。此方法已获得专利。 :)
您仍然可以阅读专利来获取灵感。
You cannot actually draw circles along the line. This approach is patented. :)
You can still read patent for inspiration.
我不知道常用的是什么,但在我看来,您可以将 Bresenham 用于 1 像素宽的线,但将其垂直或水平延伸一定数量的像素。例如,假设您的线与水平线成大约 30 度角,并且您希望它的宽度为 4 个像素。您计算出线条的垂直粗细应为五个像素。您运行 Bresenham,但对于每个像素 (x,y),您实际上绘制 (x,y)、(x,y+1)、...(x,y+4)。如果您希望线的末端变圆,请在每一端画一个圆圈。
对于过度杀伤,制作手写笔的像素图(圆形或对角线笔尖,或其他),然后绘制一组平行的布雷森汉姆线,一条对应手写笔中的每个像素。
I don't know what is commonly used, but it seems to me that you could use Bresenham for the 1-pixel-wide line, but extend it a set number of pixels vertically or horizonally. For instance, suppose your line is roughly 30 degrees away from the horizontal, and you want it to be four pixels wide. You calculate that the vertical thickness of the line should be five pixels. You run Bresenham, but for each pixel (x,y), you actually draw (x,y), (x,y+1), ... (x,y+4). And if you want the ends of the line to be rounded, draw a circle at each end.
For overkill, make a pixel map of the stylus (a circle or diagonal nib, or whatever), then draw a set of parallel Bresenham lines, one for each pixel in the stylus.
Bresenhams 计算像素覆盖率有多种变体,例如 anti-颗粒几何库;无论您想要什么质量的东西 - 您都不会说输出介质是什么,而且大多数系统都比开关 LCDS 更能支持粗细的笔。
There are variations on Bresenhams which calculate pixel coverage, such as those used in the anti-grain geometry libraries; whether you want something that quality - you don't say what the output medium is, and most systems more capable than on-off LCDS support pens with thickness anyway.