Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Plotting A Line

by Abigail-II (Bishop)
on Oct 27, 2003 at 22:11 UTC ( [id://302541]=note: print w/replies, xml ) Need Help??


in reply to Re: Plotting A Line
in thread Plotting A Line

Bresenham is an algorithm for devices that only have 1 bit pixels, on and off. You also get very nasty artifacts. A line from (0, 0) to (8, 2) would look like:
+-+-+-+-+-+-+-+-+-+ | | | | | | |*|*|*| +-+-+-+-+-+-+-+-+-+ | | | |*|*|*| | | | +-+-+-+-+-+-+-+-+-+ |*|*|*| | | | | | | +-+-+-+-+-+-+-+-+-+

Now, if all your pixels are either black or white, this isn't too bad. But the human eye is very good in seeing the non-smoothness, the "staircase" sticks out like a sore thumb.

But if you have a grayscale (or full colour) device available, there are much better techniques. One technique revolves around the observation a line needs thickness to be seen. So, if you want to draw a line from say (0, 0) to (8, 2), assume you have a rectangle of width 1 and length 2 * sqrt (17), running from (0, 0) to (8, 2). This will cover some of the pixels partially. If a pixel is covered for say, 61%, the pixel should get a gray value that's 61% of pure black.

Now, this still isn't perfect, but it's a step better. There are lots of line drawing algorithms, each of them finding a different balance between simplicity, speed, good results and avoidance of artifacts.

Abigail

Replies are listed 'Best First'.
Re: Re: Plotting A Line
by boo_radley (Parson) on Oct 28, 2003 at 13:44 UTC

    Adding to what Abigail's written:
    Michael Abrash covered the topic of eye-pleasing lines in detail in Zen of Graphics Programming. This book's quite fascinating, and pretty well written. And although most of the examples were (quite naturally) not in perl, all that's really needed to absorb most of the book's functionality are some basic math skills, typically algebra. You can also purchase a subscription to Byte magazine and get access to a seemingly similar book, where chapter 35 would be of particular interest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://302541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found