Archived

This topic is now archived and is closed to further replies.

2D Thick Line Algorithm

This topic is 5667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Thick Line Drawing Algorithm I was working on a clone of Bust A Move and just had to change the targeting arrow from the GDI to something a bit faster. It worked nicely with the GDI using a 7 pixel thick line: I couldn’t find an algorithm to draw thick lines and couldn’t think of one myself that would allow me to end the line with a point, so I just drew seven lines next to each other with Bresenham’s algorithm. I did the code for the centre line and started it up and it looked fine: Then I rotated it and…oh dear: I think the gaps are to do with rounding when the line is rotated. I think the way I’ve implemented it is rather poor. Does anyone know where I can find an algorithm for drawing thick lines of a specified width? I’d be very grateful for any help you can offer. [edited by - plague1392 on August 18, 2002 4:17:36 PM]

Share on other sites
Can''t you just draw a quad and or two triangles or more?

Share on other sites
That was my backup plan I just think a thick line algorithm would be useful to know in the future, but I can''t seem to find one anywhere.

Share on other sites
Rotate a sprite of the arrow, or a textured quad if you''re in 3D.

------------
- outRider -

Share on other sites
Do it as a simplified form of polyfiller. That''s about the only way I can think of that solves the edge problem. I tried to code several thick-line routines over the years, but always failed to come up with a general rule of how the edges should be. If you had a good polyfiller, you could make a wrapper for each type of line edges you want.

Share on other sites
Hmm... I also need a good thick line drawing algorithm. Anyone know a good reference? I STFW''ed but didnt find much.

Share on other sites
Back in qbasic, I wrote a routine to draw a thick line pixel by pixel. It basically just a simple quad filler. You''ll have to calculate the min x and max x for each row of pixels in the quad, then draw horizontal lines between the points. Basically a simple quad filler.

Share on other sites
lol
just use a bitmap with all the rotating frame.
it''s an animation of the rotation, not a calculation.
do you understand ??
i know that in bust a move, the rotating arrow is from 0 to Pi.
so store the rotating arrow animation from 0 to Pi step Angle and draw the corespondant frame.

Share on other sites
I sorted it out last night, but I'm still very interested if anyone does have a link to an algorithm for drawing thick lines.

I probably shouldn't have asked the question specific to a problem because I could think of a number of ways to solve the specific problem, and was really just after the thick line drawing algorithm rather than suggested solutions. I mainly described the problem to show I had taken a shot at it myself and hadn't just come and posted here without trying myself first.

Anyway, thanks to everyone for putting the effort in to try and help me (well, everyone but the guy directly above). It's very much appreciated.

[edited by - plague1392 on August 19, 2002 9:26:37 AM]

Share on other sites
Check your mail, Plague1392.

Share on other sites
i don''t know exactly but i think there is nothing like a thick line algorithm. actually you have only four possibilitis:

1. draw line beside line (what you already did)
2. draw a quad with lines and fill the quad (like prior suggested)
3. use a bitmap (like prior suggested) fix (from a file) and rotate
4. create a bitmap on the fly and calculate for every frame the points of the line (but that doesn''t make sense actually ;o))).

Share on other sites
Alimonster sent me some information regarding the “moving pen” method of drawing lines, which seems a good solution because it allows for even thicknesses and does not produce the problem where the end of the line is horizontal (as happens if you set the pixels either side of a 1 pixel thick line).

I’ve been looking for a web site describing this method for anyone else who may be interested, but unfortunately the best I could find was:

http://fcggpc41.icg.tu-graz.ac.at/grabner/BACG_Online/node51.html

It’s not a great description but it may be useful.

Share on other sites
this algorithm is probably too unefficient, but it can create very nice anti-aliased, thick lines.

for every pixel that could change colour after you draw your line (you could use a bounding box, or optimize it further by figuring out a smaller area), you check the closest distance to the line. if u just want a thick line, then change pixel colour to line colour if the distance is less than or equals to (line width * 0.5). if u want anti aliased line, then make it a smooth gradient or something. meaning the pixel colour will change colour closer to the line colour, depending on how far it is from the line. or you could use a sine wave here, to make the line bright in the center, and anti-aliased (more transparent) on the edges.

but like i said, that''s pretty unefficient. but i''m sure u could find great line drawing algorithms if you search google.com. good luck to you.

---
shurcool
wwdev

Share on other sites
i think today''s ur lucky day!

well, i think i found something that may be of an interest to you. check this out!

hope that helps.

---
shurcool
wwdev

Jim Blinn''s got a nice book called "Dirty Pixels" which is a nice little 2d drawing algo book there are about 50 different circle drawing algos, among other things like line drawing algos. It''s a measely $19.99 and might be a worthy investment for problems like this. Share this post Link to post Share on other sites quote: Original post by Anonymous Poster Jim Blinn''s got a nice book called "Dirty Pixels" which is a nice little 2d drawing algo book there are about 50 different circle drawing algos, among other things like line drawing algos. It''s a measely$19.99 and might be a worthy investment for problems like this.

Actually that''s the wrong book sorry about that. The jim blinn book i was speaking of is "Jim Blinn''s Corner" Here is a link : http://www.amazon.com/exec/obidos/ASIN/1558603875/ref=pd_sr_ec_ir_b/102-5859057-5368901

Share on other sites
bresenham thick line algorithm:

http://homepages.enterprise.net/murphy/thickline/