Bresenham line algorithm (thickness)
Asked Answered
S

3

5

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?

Stroke answered 15/9, 2009 at 15:23 Comment(1)
A single pixel line is really a 1-pixel wide rectangle. When you're drawing a wider line, you can use any polygon drawing algorithm. This will clarify not only how the line is rendered, but also how to deal with the line caps and anti-aliasing, should you choose to.Observer
I
7

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

Impure answered 15/9, 2009 at 15:30 Comment(4)
Patents like this are stupid. Those people deserve to be shot.Soricine
What the point of a patent website that doesn't show (1) the patent issue date and (2) the patent expiration date?Planish
It's not a patent. It's a patent application (not yet granted - and it shouldn't be granted).Cavendish
Updates from the future: patent application has been abandoned patents.google.com/patent/US20090096794A1/en. Hopefully @Soricine didn't shoot the poor sods.Rodrich
G
3

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.

Grapheme answered 15/9, 2009 at 15:44 Comment(0)
K
2

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.

Kimbrough answered 15/9, 2009 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.