Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Line drawing with Bresenham more than one pixel thick

167 views
Skip to first unread message

Gazza

unread,
Apr 8, 2010, 4:35:48 AM4/8/10
to
Hello,

I am using the Bresenham algorithm to draw single pixel lines with no
problems. However I would like to draw some lines which are more than
one pixel thick. Is there a modification to this algorithm that I can
use or can anyone point me to an algorithm or resource that I can use
to investigate / achieve this?

Many thanks in advance

Gary

Ian Collins

unread,
Apr 8, 2010, 4:56:37 AM4/8/10
to

Do you have a C question? You appear to posted to the wrong group.

--
Ian Collins

Gazza

unread,
Apr 8, 2010, 8:07:29 AM4/8/10
to

The question is related to C as that is what the algorithm is coded in
which I am currently using. I searched this group and there are
several questions relating to this algorithm already so I thought that
it would be a good forum to ask as people were using it already and
may had had the same issue or know about adapting it to construct
lines of more than one pixel thick. Any help would be appreciated.

Gary

Jens Thoms Toerring

unread,
Apr 8, 2010, 8:59:04 AM4/8/10
to
Gazza <gary...@googlemail.com> wrote:
> On 8 Apr, 09:56, Ian Collins <ian-n...@hotmail.com> wrote:
> > On 04/ 8/10 08:35 PM, Gazza wrote:
> > > I am using the Bresenham algorithm to draw single pixel lines with no
> > > problems. However I would like to draw some lines which are more than
> > > one pixel thick. Is there a modification to this algorithm that I can
> > > use or can anyone point me to an algorithm or resource that I can use
> > > to investigate / achieve this?
> >
> > Do you have a C question?  You appear to posted to the wrong group.

> The question is related to C as that is what the algorithm is coded in


> which I am currently using.

Just because you write something in C doesn't make it on-topic
in a group about the C language (and not about everything that
can be written in this language - since C is a Touring-complete
language there otherwise would be nearly no limit to the topi-
cality;-).

> I searched this group and there are
> several questions relating to this algorithm already

The last time the word "bresenham" was mentioned in this group
was, at least according to Google, about 9 years ago, and here's
a short citation from that thread from 2001:

| It is off topic here; the newsgroup for computer graphics algorithms
| is, perhaps surprisingly, comp.graphics.algorithms.

I don't know if comp.graphics.algorithms still exists and is
active, otherwise I would guess that you will have a lot more
luck in e.g. comp.programming where discussions of specific
algorithms is definitely on-topic.

Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de

Ersek, Laszlo

unread,
Apr 8, 2010, 10:47:27 AM4/8/10
to

Have you considered the brute force idea of:
- compute a slope orthogonal (.) to the line's slope (*)
- compute the vertices of a rotated rectangle based on line thickness (#)
- rasterize the rectangle "somehow":

#o
. oo
.** oo
. ** oo
#o ** oo
oo ** o#
oo ** .
oo **.
oo .
o#

You could split this rectangle into three parts, an upper triangle, a
middle parallelogram, and a lower triangle. You could write a single loop
scanning the Y axis top-down, maintaining a "phase" flag or so. Or you
could write three loops.

Phase 1: track original slope on the right with Bresenham's, track the
orthogonal slope on the left with Bresenham's, draw a horizontal segment
between them, for each distinct Y value.

Phase 2: switch to the original slope on the left.

Phase 3: switch to the orthogonal slope on the right.

You'll have to "unpack" the drawline() function and "fuse" two instances,
ie. execute two drawline()'s in lockstep, in parallel.

http://en.wikipedia.org/wiki/Loop_fusion

(This idea is worth exactly as much as you've paid for it. And I'm sure
c.l.c is liberal enough, all semblance notwithstanding, to allow me to
veer off to this exact topic :P)

lacos

Seebs

unread,
Apr 8, 2010, 1:01:04 PM4/8/10
to
On 2010-04-08, Gazza <gary...@googlemail.com> wrote:
> The question is related to C as that is what the algorithm is coded in
> which I am currently using.

That doesn't make it about C.

Would the answer to your question be changed in ANY way by using perl?
No, it would not. Would it be changed in ANY way by a shift from pre-K&R
C to C99? No, it would not.

It hasn't got anything to do with the language.

The issue here is that the topic here is the C language, not any program
which happens to be in C. If the issues you're encountering aren't specific
to a given language (and they aren't), you probably want comp.programming
or somesuch.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Dann Corbit

unread,
Apr 8, 2010, 1:32:59 PM4/8/10
to
In article <c8177466-965a-4b49-9d11-425251830fb2@
11g2000yqr.googlegroups.com>, gary...@googlemail.com says...

You want news:comp.graphics.algorithms
FAQ:
http://www.faqs.org/faqs/graphics/algorithms-faq/

Uno

unread,
Apr 9, 2010, 4:31:16 AM4/9/10
to
Jens Thoms Toerring wrote:
> Gazza <gary...@googlemail.com> wrote:

>> The question is related to C as that is what the algorithm is coded in
>> which I am currently using.
>
> Just because you write something in C doesn't make it on-topic
> in a group about the C language (and not about everything that
> can be written in this language - since C is a Touring-complete
> language there otherwise would be nearly no limit to the topi-
> cality;-).

Your mispelling of Dr. Turing's name is a funny little mini-error,
because I believe he has the same name as you. In Berlin we would say
the place name with an initial 'd' instead of 't'. Wasn't it a Bezirk
in the ddr?
--
Uno

christian.bau

unread,
Apr 9, 2010, 9:08:16 PM4/9/10
to

Sure. But I think you would first have to define what you actually
want to draw. If the line is say ten pixel thick, do you want to draw
a rectangle rotated into the right position, or a parallelogram?

Dann Corbit

unread,
Apr 9, 2010, 11:06:50 PM4/9/10
to
In article <ef2503e6-6606-4c72-94fb-ce3fc3588c41
@q23g2000yqd.googlegroups.com>, christ...@cbau.wanadoo.co.uk says...

Typically neither.

When I had the same problem, I inserted pie slices into the gaps where
the segments change direction (for non-raster devices like pen
plotters). If you have a raster device, then you can just add a circle
the same diameter as the the line segments at the ends of all interior
direction changes.

Gazza

unread,
Apr 12, 2010, 7:23:20 AM4/12/10
to
On 10 Apr, 04:06, Dann Corbit <dcor...@connx.com> wrote:
> In article <ef2503e6-6606-4c72-94fb-ce3fc3588c41
> @q23g2000yqd.googlegroups.com>, christian....@cbau.wanadoo.co.uk says...

Thanks for all of your comments. I will be more careful next time when
posting a question to a group. I thought that more or you would be
interested in solving the issue than complaining about using the wrong
group. Many apologies if I offended anyone by asking a question I
thought that you would be able to answer as C programmers. Special
thanks to those who actually gave some guidance.

Gary

Keith Thompson

unread,
Apr 12, 2010, 12:01:54 PM4/12/10
to
Gazza <gary...@googlemail.com> writes:
[...]

> Thanks for all of your comments. I will be more careful next time when
> posting a question to a group. I thought that more or you would be
> interested in solving the issue than complaining about using the wrong
> group. Many apologies if I offended anyone by asking a question I
> thought that you would be able to answer as C programmers. Special
> thanks to those who actually gave some guidance.

Part of the purpose of redirecting a question to a more appropriate
group is that you can get more and better answers there, and those
answers can be checked by more people who are actually familiar with
the topic.

The other part of the purpose is that the signal-to-noise ratio here
is low enough as it is.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Seebs

unread,
Apr 12, 2010, 12:41:52 PM4/12/10
to
On 2010-04-12, Keith Thompson <ks...@mib.org> wrote:
> Gazza <gary...@googlemail.com> writes:
> [...]
>> Thanks for all of your comments. I will be more careful next time when
>> posting a question to a group. I thought that more or you would be
>> interested in solving the issue than complaining about using the wrong
>> group. Many apologies if I offended anyone by asking a question I
>> thought that you would be able to answer as C programmers. Special
>> thanks to those who actually gave some guidance.

> Part of the purpose of redirecting a question to a more appropriate
> group is that you can get more and better answers there, and those
> answers can be checked by more people who are actually familiar with
> the topic.

Yes. I could give all sorts of advice about line drawing algorithms, but
you'd have to be pretty dumb to take my advice on it, because the sole
extent of my actual experience is refactoring a 3-page function written
in pascal into a 15-line function in C for use in a roguelike game.

I would guess that the vast majority of C programmers have never had
any reason to write a line-drawing algorithm outside of some kind of
toy project in school, but that the vast majority of graphics programmers,
regardless of language, will be at least basically familiar with the
range.

Basically, it's silly to expect people to be more interested in solving
a problem that's of no interest to them and of no relevance to their fields
of study and work, than they are in suggesting that you ask people whose
line of work it would be in.

Would you come to a group of mathematicians to ask for advice about
double-entry bookkeeping, on the grounds that it's done by some kind of
arithmetic, which is a branch of mathematics?

0 new messages