A fast integer line-drawing algorithm invented by Jack Bresenham, or one of a family of algorithms derived from the original.
Questions tagged [bresenham]
173 questions
2
votes
0 answers
Any alternative to bresenham's circle algorithm to avoid overdraw?
I use Bresenham's circle algorithm.
But I've noticed as you will see by yourself by running the code below that this algorithm draws sometimes multiple times the same pixel.
What I usually do is parse all the anterior coordinates to check if it…

JSmith
- 4,519
- 4
- 29
- 45
2
votes
1 answer
How does Bresenham algorithm simultaneously track x AND y error in one variable?
Consider this snippet from Rosetta Code (in the C language):
void line(int x0, int y0, int x1, int y1) {
int dx = abs(x1-x0), sx = x0dy ? dx : -dy)/2, e2;
for(;;){
…

Marco Merlini
- 875
- 7
- 29
2
votes
2 answers
Make Bresenham's Algorithm keep cycling
Like this (it's not accurate)
How can I change the Bresenham line algorithm to keep cycling into itself and create this effect:
(Drawning not accurate)
I have the basic line with 2 coordinates:
drawBresenhamLine = function (x0, y0, x1, y1) {
…

Diego Vallejo
- 55
- 1
- 7
2
votes
3 answers
Midpoint circle without duplicates?
I have some code to generate grid coordinates (SDL_Point just contains two ints for x and y) with a circle shape:
std::vector circle(const SDL_Point & start, const int radius)
{
int x{ radius }, y{ 0 };
int xChange{ 1 - 2 * radius…

JoePerkins
- 579
- 5
- 12
2
votes
1 answer
JavaFX rendering / image manipulation
I made a little JavaFX app generating longshadows. At this point I struggle with the rendering (see picture).
The missing line on the rectangle's corner seems hard to fix. Changing the loop, which applies the manipulation, will mess up other…

Martin Pfeffer
- 12,471
- 9
- 59
- 68
2
votes
2 answers
Looking for a fast outlined line rendering algorithm
I'm looking for a fast algorithm to draw an outlined line. For this application, the outline only needs to be 1 pixel wide. It should be possible, whether by default or through an option, to make two lines connect together seamlessly, if they share…

Thomas O
- 6,026
- 12
- 42
- 60
2
votes
1 answer
Optimisation of Shadow Casting Python
I have been working on a Shadow Caster for a small RPG I'm doing.
The trouble I have is that when I use it in my game it is just way way way to slow and induces a horrible lag.
Please do not be too frighten by the lenght of the post. It is fairly…

Sorade
- 915
- 1
- 14
- 29
2
votes
0 answers
DDA Algorithm and Bresenham Algorithm
I have been studying DDA and Bresenham algorithms for line drawing and am curious about one thing.In both the algorithms,we consider a pixel grid to be of unit size and perform further steps.My question is if I change my grid size to say 0.5*0.5…

Yash Lekhwani
- 21
- 3
2
votes
2 answers
Understanding Bresenham's error accumulation part of the algorithm?
I'm having issues understanding how the error accumulation part works in Bresenham's line drawing algorithm.
Say we have x1 and x2. Let's assume that x1 < x2, y1 < y2, and (x2 - x1) >= (y2 - y1) for simplicity:
Let's start with the naive way of…

vexe
- 5,433
- 12
- 52
- 81
2
votes
1 answer
Anti-aliasing Bresenham's line not working as expected
I'm trying to implement bresenham's line drawing with anti-aliasing using this article:
http://members.chello.at/~easyfilter/bresenham.html
And here's the function:
void ColoringScene::drawLineAA(int x0, int y0, int x1, int y1, int r, int g, int b,…

Makalele
- 7,431
- 5
- 54
- 81
2
votes
2 answers
Better line selection than using Bresenham algorithm?
I'm drawing lines on an HTML canvas, and use a less precise 2d-array (representing blocks of 10x10 pixels) in which I 'draw' lines with Bresenham's algorithm to store line-ids, so I can use that array to see which line is selected.
This works, but I…

Eindbaas
- 945
- 1
- 8
- 16
2
votes
1 answer
Bresenham Integer Equation (Not just the algorithm)
I am looking for an equation for a basic version of the bresenham line algorithm that would allow me to calculate the position of the Y value if the X value is known.
The X is always positive and always larger then the Y.
The loop just adds 1 to…

Dave3891
- 63
- 1
- 3
2
votes
1 answer
Can this line drawing algorithm be optimized? - SDL
For a project I have been working on, the ability to draw lines with a gradient (I.E. they change color over the interval they are drawn) would be very useful. I have an algorithm for this, as I will paste below, but it turns out to be DREADFULLY…

BrainSteel
- 669
- 5
- 17
2
votes
2 answers
Triangle Rasterization: Bresenham's in 3D
I am looking for a 3D implementation of triangle rasterization using Bresenham's line drawing algorithm. Namely, I have this source:
http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html,
however the algorithm is in…

Cenk Baykal
- 159
- 3
- 7
2
votes
1 answer
Direct Bresenham
There is this well known algorithm for drawing lines by Bresenham, Wikipedia has very good article about it: http://en.wikipedia.org/wiki/Bresenham's_line_algorithm.
The main loop iteratively calculates x or y coordinates by adding or subtracting 1…

Ecir Hana
- 10,864
- 13
- 67
- 117