how do I create a line of arbitrary thickness using Bresenham?
digitize a line from (10,12) to (15,15) on a raster screen using bresenham's straight line algorithm
bresenham line drawing algorithm python
bresenham's line algorithm calculator
thick line drawing
bresenham's line algorithm flowchart
fast line drawing algorithm
thick line style in computer graphics
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?
The language I am using is C.
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.
So, following a comment below, the process to do this would be:-
- Create a rectangle the same length as the required line and width equal to the desired width, so (0,0) to (width,length)
- Rotate and translate the rectangles corner coordinates to the desired position using a 2D transformation
- Rasterise the rotated rectangle, either using a hardware accelerated renderer (an OpenGL quad for example*) or use a software rasteriser. It can be rendered using a quad rasteriser or as a pair of triangles (top left and bottom right for example).
Note *: If you're using OpenGL you can also do Step 2 at the same time. 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.
danbar/murphy_line_draw: A modified version of Bresenham's line , By modifying Bresenham's line algorithm to plot rectangles instead of pixels, it is possible to draw lines of any thickness. algorithm - how do I create a line of arbitrary thickness using Bresenham? 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? The langu…
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.
Algorithm to Draw a Line of Arbitrary Thickness - Manuals, 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� Bresenham's Line Algorithm is a way of drawing a line segment onto a square grid. It is especially useful for roguelikes due to their cellular nature. A detailed explanation of the algorithm can be found here. In libtcod it is accessible using line(x1, y1, x2, y2, callback). Below are several hand-coded implementations in various languages.
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 Geometry, a 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.
how do I create a line of arbitrary thickness using Bresenham?, 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� Bresenham's Line Algorithm Lecture 3 / 3rd Class / 2016-2017 2 Ms. C. Rusul Mohammed Bresenham's algorithm is generalized to lines with arbitrary slope by considering the symmetry between the various octants and quadrants of the xy plane. For a line with positive slope greater than 1, we interchange the roles of the x and y directions.
For best accuracy, and also good performance for thicker lines especially, you can draw the line as a polygon. Some pseudo code:
draw_line(x1,y1,x2,y2,thickness) Point p; angle = atan2(y2-y1,x2-x1); p.x = x1 + thickness*cos(angle+PI/2); p.y = y1 + thickness*sin(angle+PI/2); p.x = x1 + thickness*cos(angle-PI/2); p.y = y1 + thickness*sin(angle-PI/2); p.x = x2 + thickness*cos(angle-PI/2); p.y = y2 + thickness*sin(angle-PI/2); p.x = x2 + thickness*cos(angle+PI/2); p.y = y2 + thickness*sin(angle+PI/2); draw_polygon(p,4)
And optionally a circle could be drawn at each end point.
Murphy's Modified Bresenham Line Algorithm, a) Use Bresenham's algorithm to draw a line from P(3,3) to Q(10,5). Repeat How would you modify Bresenham's algorthm to draw lines of arbitrary thickness ? algorithm - how do I create a line of arbitrary thickness using Bresenham? 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? The langu…
Week 9 Tutorial Solutions, 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� Bresenham’s Line algorithm :-Bresenham’s line algorithm uses only integer addition and subtraction and multiplication by 2, and we know that the computer can perform the operations of integer addition and subtraction very rapidly. The computer is also time-efficient when performing integer multiplication by powers of 2.
Murphy's Modified Bresenham Line Algorithm, In Sect. 3.2 an efficient line drawing algorithm based solely on integer For the generalisation of the midpoint or Bresenham algorithm to circles , another the value of the decision variable d is not computed in each step by inserting the midpoint For drawing arbitrary curves, or at least continuous curves, the plot of the� Here you will get program for bresenham’s line drawing algorithm in C and C++. This algorithm is used in computer graphics for drawing line. The program will work in Turbo C or Turbo C++ compiler as it uses graphics.h header file. Make sure to change the path of BGI folder inside initgraph() function according to your system.
Drawing Lines and Curves (Introduction to Computer Graphics , Since OpenGL 3.0 lines with thickness larger than 1 are not You don't need arbitrary shift if you make the fractional part a multiple of the word� In any 2-Dimensional plane if we connect two points (x0, y0) and (x1, y1), we get a line segment. But in the case of computer graphics we can not directly join any two coordinate points, for that we should calculate intermediate point’s coordinate and put a pixel for each intermediate point, of the desired color with help of functions like putpixel(x, y, K) in C, where (x,y) is our co
The Beauty of Bresenham's Algorithm, for plotters can be attributed to one man, Jack Bresenham. Lecture 5. Slide 2 Uniform thickness and brightness. I. Accuracy (Turn Draw a line by clicking and dragging on the pixel grid shown with the left mouse button. less than, greater than or equal, and less than or equal to zero (not an arbitrary value). G. Lecture 5. The basic Bresenham algorithm Consider drawing a line on a raster grid where we restrict the allowable slopes of the line to the range .. If we further restrict the line-drawing routine so that it always increments x as it plots, it becomes clear that, having plotted a point at (x,y), the routine has a severely limited range of options as to where it may put the next point on the line:
- Retagged "language-agnostic" since the implementation language is not really relevant.
- here is a related SO question: stackoverflow.com/questions/101718/…
- @banister: you got some demo to share with us?
- I didn't got your solution. Can you elaborate please.
- That would only work if the line is perfectly vertical or horizontal.
- @Jonathan: A line of arbitary thickness can be thought of as a rotated rectangle so isn't limited to just vertical or horizontal lines. Of course, drawing rectangles at arbitary angles will result in the jaggies unless you add some anti-aliasing to smooth things off a bit. Doing anti-aliasing is a whole separate question.
- @Skizz My mistake. I was assuming that a rotated rectangle would require actually rotating a rectangle, which would be difficult for someone trying to implement Bresenham's algorithm. However, you can draw a rotated rectangle using two triangles, so I withdraw my criticism. If you update your answer to describe how to draw a rotated rectangle, I will upvote.
- If I could, I would upvote this answer more, because it's the only one that directs the reader to a clean, working implementation in C - just as the OP asked for.
- That is so clever!
- In a way this is reducing the problem to a more complex one. In order to get it to work (in Python), I had to adjust things, though: a) exchange the sin and the cos. b) instead of multiplying by thickness, multiply by thickness/2.0.
- @Ant6n I think it's the angle that is wrong. This should be
- How would you like to implement
draw_polygon(or, in fact,
- How to implement fill_polygon is quite a broad question. There are various techniques depending on the environment and other requirements. In most cases there are suitable libraries available with functions for basic drawing (hopefully using hardware acceleration). Otherwise a common technique (if the polygon is guaranteed to be completely convex such as in this case) is having two arrays containing the x-coordinates of each side of the polygon and draw vertical lines between them. But you should probably search for questions about drawing filled polygons specifically to get more details.