Murphy's Modified Bresenham Line Drawing Algorithm An Algorithm for drawing thickened lines Background This page describes an algorithm for drawing thickened lines on a display or picture grid. It is based on an extension to Bresenham's Line drawing algorithm - see: "J. The inner loop and most of the outer loop require only addition, and comparision testing.
This produces an efficient algorithm. The line thickness can be a real number, is is not necessary to be an integer. The perceived line thickness does not vary for lines of different orientations. It is possible to have a thickness which is a function of the distance from the start point - the thickness varies along the line, giving the possibility of depth-cueing Z-axis effects.
General Principle In order to draw a thick line, you need to draw a number of parallel single thickness lines. There are 2 ways to do this: Draw lines perpendicular to the ideal line stepping along it. Draw lines parallel to the ideal line and step perpendicularly. The document describes algorithms for each of the above situations. Both algorithms have two Bresehham loops, one inside the other. The outer loop does the 'stepping' and the inner loop draws single pixel lines.
The key aspect of the technique is that the outer loop contains just the right information for the inner loop. This is important as the inner loop must be started in the 'correct' phase of its cycle so that the diagonal moves occur in phase.
The outer loop's difference terms are passed to the inner loop to accomplish this. Another aspect of the technique is that an 'extra' inner loop cycle is required whenever the outer loop and the inner loop do a diagonal move together. In this case the outer loop does a 'double square' move rather than a diagonal move. When the outer loop detects this condition it performs a square move, calls the inner loop, does another square move at right angles and calls the inner loop again. In this way a diagonal move is achieved but there are two calls to the inner loop.
Demonstration Program The original paper is not particularly clear. However, I have produced a thick line drawing demonstration program which better illustrates the technique K approx.
This is an Object Pascal Delphi 1 program complete with source code. I have rushed the programming and so the demo is NOT well tested. Please be careful if you run it by saving all important data in other programs first. Because the loop end conditions are tricky to get right, it is just possible that the demo may get into an infinite loop. Drawing lines in other octants is obtained by defining the 4 types of moves required by the loops. I hope to illustrate this in a future version of the demo.
Also the thick line is drawn to one side of the ideal line. This will be corrected in a future version. Variations The demo program illustrates one method by which line patterns may be formed. In this case the pattern is a function of p,q and so the pattern is with respect to the line orientation.
An alternative is to make the pattern a function pt. The line thickness variation is illustrated using the 'thickfunct' which shows how the thickness can be varied along the length of the line. This uses the Thick Perp algorithm. Screen Shot The following is a screen shot of the demonstration program: This shows a line drawn from 4 2 to 20 8 with a line thickness of 5. It shows the sequence order in which the pixels are drawn 0,1,2, The start points for the perpendicular lines are 0,6,12,17,22,27,32,37,42,Skip to Main Content.
Email Address. Sign In. Access provided by: anon Sign Out. Line-drawing algorithms for parallel machines Abstract: The fact that conventional line-drawing algorithms, when applied directly on parallel machines, can lead to very inefficient codes is addressed. It is suggested that instead of modifying an existing algorithm for a parallel machine, a more efficient implementation can be produced by going back to the invariants in the definition.
Popular line-drawing algorithms are compared with two alternatives; distance to a line a point is on the line if sufficiently close to it and intersection with a line a point on the line if an intersection point. For massively parallel single-instruction-multiple-data SIMD machines with thousands of processors and upthe alternatives provide viable line-drawing algorithms. Because of the pixel-per-processor mapping, their performance is independent of the line length orientation.
Article :. Date of Publication: Sept. DOI: Need Help?Point plotting is accomplished by converting a single coordinate position furnished by an application program into appropriate operations for the output device.
With a CRT monitor, for example, the electron beam is turned on to illuminate the screen phosphor at the selected location. Line drawing is accomplished by calculating intermediate positions along the line path between two specified end points positions. An output device is then directed to fill in these positions between the end points. Digital devices display a straight line segment by plotting discrete points between the two end points.
Discrete coordinate positions along the line path are calculated from the equation of the line. For a raster video display, the line color intensity is then loaded into the frame buffer at the corresponding pixel coordinates. Pixel positions are referenced according to scan-line number and column number pixel position across a scan line. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line.
Digital Differential Analyzer DDA algorithm is the simple line generation algorithm which is explained step by step here. The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each step choose between two different y coordinates.
For example, as shown in the following illustration, from position 2, 3 you need to choose between 3, 3 and 3, 4. You would like the point that is closer to the original line. You can use these to make a simple decision about which pixel is closer to the mathematical line. This simple decision is based on the difference between the two pixel positions.
Remember, the coordinate changes occur along the x axis in unit steps, so you can do everything with integer calculations. Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van Aken. Now you need to decide whether to put the next point at E or N. This can be chosen by identifying the intersection point Q closest to the point N or E. If the intersection point Q is closest to the point N then N is considered as the next point; otherwise E.
If the intersection point Q of the line with the vertical line connecting E and N is below M, then take E as the next point; otherwise take N as the next point. Your email address will not be published. Properties of Binary relation.
Parallel algorithms for line generation
Closure of Relations and Equivalence Relations. Equivalence relations. Partial order relation. Functions and its types. Composition of function. Recursively Defined Functions. Normal Subgroup. Permutation groups. Logical implication. Normal forms. We have unique plans for you. Rahul singh.Here are several versions, ending with Bresenham's algorithm. The point of this is to use the simplest possible operations.
Track the deviation of the current y from the perfect line. When the deviation gets too large, increment y, and decrement the deviation. Then we get:. The next problem is that modern computers use a pipelined architecture, where different stages of several instructions are processed in parallel. However, when there is a conditional, the computer can't tell what the next instructions are, and so is forced to flush the pipeline.
Therefore we want to eliminate the conditional in the inner loop. The following assumes that the right shift is arithmetic, which it is on the Sun. The following is expanded about the origin. This is better, but there are more nonzero coefficients, which means that it is slower. A Chebyshev series, which tries to minimize the maximum error over an interval beats a Taylor series:. This has a max error of 1. We could get as good as either Taylor with many fewer terms than they.
Bresenham’s Line Generation Algorithm
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. 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. 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. You cannot actually draw circles along the line. This approach is patented. 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. 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 whateverthen draw a set of parallel Bresenham lines, one for each pixel in the stylus.
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.
Learn more. Bresenham line algorithm thickness Ask Question. Asked 10 years, 6 months ago.
Active 10 years, 6 months ago. Viewed 9k times. Perhaps I could somehow draw half circles depending on the angle? Any input would be appreciated. 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.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.
I am currently using Bresenham's algorithm to draw lines but they are of course one pixel in thickness. My question is what is the most efficient way to draw lines of arbitrary thickness? I think the best way is to draw a rectangle rather than a line since a line with width is a two dimensional object. Tring to draw a set of parallel lines to avoid overdraw to reduce write bandwidth and underdraw missing pixels would be quite complex.
It's not too hard to calculate the corner points of the rectangle from the start and end point and the width. Of course, using OpenGL does mean understanding OpenGL big and complex and this application may make that a tricky thing to implement at such a late stage in development.
Take another Bresenham loop and use it to modify the start and end position of original line in rectangular direction.
Problem is to efficently find the right starting point and not to draw any pixel twice or skip a pixel while drawing next line. Working and tested C code is available from Github C code. Here a test page including a few sample lines created by this code. The black pixels are the starting points for the algorithm. Here is a paper and Delphi implementation of a modified version of Bresenham's algorithm for drawing thickened lines.
You may also want to take a look at Anti-Grain Geometrya library for high-quality and high-performance software rendering of 2D graphics. Take a look at the demo page to get an idea of what it can do.
The easiest way to create a line of almost arbitrary thickness would be to first do a bresenham, then apply as many dilation iterations as you wish. Each dilation pads both sides of your line equally, but by using different masks, you can achieve even as well as uneven thickness. EDIT : It is also worth noting that this method has the nice feature of being easily generalizable to 3D, because both Bresenham and dilation are easily generalizable to 3D.
I do this quite often to generate images of fibers and spheres for porous media simulations. I have a nice simple way do this using a very standard image analysis technique know as the 'distance transform'. This requires having access to some image analysis package. I use Python with Scipy, so this is no problem. Here is a demo to convert randomly distributed points into spheres:. And that is it! The distance transform can be slow for very large images, but there are efficient version out there.
For instance, ImageJ has a parallelized one. Obviously, to create thick fibers you just create your image of thin ones, then apply the steps 2 and 3 above. For my embedded thermal printer application, using Bresenham's algorithm, the line was way too thin. I don't have GL or anything fancy. I ended up simply decrementing the Y value and drawing more lines under the first one. Each number of thickness added another line.A new, parallel approach for generating Bresenham-type lines is developed.
Bresenham's line algorithm
Coordinate pairs which approximate straight lines on a square grid are derived from line equations. These pairs serve as a basis for the development of four new parallel algorithms. One of the algorithms uses the fact that straight time generation is equivalent to a vector prefix sums calculation.Computer Graphics: Bresenham's Line Algorithm
The algorithms execute on a binary tree of processors. Each node in the tree performs a simple calculation that involves only additions and shifts. All four algorithms have time complexity O log 2 n where n in the form 2 m denotes the number of points generated and n -1 is the number of processors in the tree.
This compares to O n for Bresenham's algorithm executed on a sequential processor. Pipelining can be used to achieve a constant time per line generation as long as line length is less than n. This is a preview of subscription content, log in to check access. Rent this article via DeepDyve. Foley and A. Van Aken and M. Ladner and M. Fischer, Farallel Prefix Computation, J.
ACM27 4 — October Meijer and S. JPP16 2 — Cole and U. Download references.
Reprints and Permissions. Parallel algorithms for line generation. Int J Parallel Prog 19, — Download citation. Received : 15 April Revised : 15 October Issue Date : October Search SpringerLink Search. Abstract A new, parallel approach for generating Bresenham-type lines is developed. Immediate online access to all issues from Subscription will auto renew annually. Taxes to be calculated in checkout.
References 1. Google Scholar 2. Google Scholar 4. Google Scholar 5.