Have I told you that my area of expertise is Computer Graphics? Well, now you know.
So, for that matter, our first algorithm should be CG related. I've chosen one that everybody can ascertain its existence. May I present you the Line Drawing Bresenham's Algorithm.
Given 2 points in a discrete plane, this algorithm draws a line connecting these two points. Have you ever thought about how the lines are draw in your amazing GUI? Well, it is done by connecting sequential pixels, which is easy if the line is absolutely horizontal or vertical. But if the line has some slope, than we need a line drawing algorithm.
In first place, this algorithm could be used in every computer system today, so even a plant could agree that it is useful (right, I can tell if this algorithm was really used in a raster computer system like the ones implemented Next or X11, but could be it or some variation/evolution. Some graphics cards do implement line drawing algorithms based on the original Bresenham code).
The algorithm is was first written in 1962, and the paper was published in 1965 at IBM Systems Journal. Then, in a world where computing power was very very expensive, floating point calculations were yet more expensive (no, no hardware acceleration kids), and the work had to get done, this algorithm came to be perfect.
It is great cause avoid floating point calculations, multiplications and fractions. So, using just addition and subtraction with integer numbers (some implementations use bit shift to accomplish integer multiplication/division by 2, which is fast even on simple processors) the algorithm is also really fast. It works trying to draw the perfect line by finding the next pixel to draw. As more the one pixel can be chosen, the algorithm select the best by attributing errors to each option. The one pixel with the best error value is next in the line.
I have coded myself this algorithm during my Bachelors, but of course I have not this code anymore. Wikipedia has an implementation here that, to me, looks correct. Also the original (first implementation) can be found here, and the paper here.
With all of theses positive points, our number one take leave of our presence, thank you and say to wait for the next one in the line.
References: Jack E. Bresenham, Algorithm for Computer Control of a Digital Plotter, IBM Systems Journal, 4(1):25-30, 1965. On-line at http://researchweb.watson.ibm.com/journal/sj/041/ibmsjIVRIC.pdf
Reprinted in Interactive Computer Graphics, Herbert Freeman ed., 1980, and Seminal Graphics: Pioneering Efforts That Shaped The Field, Rosalee Wolfe ed., ACM SIGGRAPH, 1998.
well, i must agree, it's one of the main algorithms everyone should master in any CL. such a simple linear thing ... :) but please check the hyper-link to bresenham's paper, it doesn't work!
ReplyDeletenice job anyway!
greetings
Thanks !
ReplyDeleteI'll check the links. Let's hope the paper and source code are still available.