views:

811

answers:

3

Hello.

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?

+1  A: 

You cannot actually draw circles along the line. This approach is patented. :) You can still read patent for inspiration.

alex
This is just paper right, what about pseudo algorithm? :)
Patents like this are stupid. Those people deserve to be shot.
ryeguy
A: 

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.

Beta
+1  A: 

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.

Pete Kirkham