Locating Pixels with Bresenham's line algorithm

In summary, the conversation is about a person looking for help in locating the pixels of a line drawn from (0,0) to (-4,-8) using Bresenham's algorithm. They have tried various algorithms but have not found a solution. Another person suggests using the equation of the line and replacing x with the desired pixel location to find the corresponding y value. The original person also mentions trying Bresenham's algorithm, but had difficulty with negative slopes. They then share a solution of reversing the x and y axes and using Bresenham's algorithm.
  • #1
armin11
66
0
hi,I wanted to locate the pixels of a line drawn from (0,0) to (-4,-8) with bresenham's algorithm.I couldn't find a suitable algorithm for finding these pixel locations.Can anyone help me please?(the algorithm can be without computer and work by hand)
 
Physics news on Phys.org
  • #2
I've searched so much and tried every algorithm but couldn't reach a reaspnable solution ?!
 
  • #3
Try the following:

Write the equation of the line you want to draw. y = ax + b

Lets say you want to find the pixel located at x = -2; to do that you replace x in the equation of the line resulting in y = -2a + b, then y should be the lowest integer closest to -2a + b.
 
  • #4
Your question doesn't make sense. You are asking how to find the pixels drawn by Bresenham's algorithm. There is an obvious approach: use Bresenham's algorithm.
 
  • #5
thanks guys,I tried but apparently bresenham didn't work for minus slopes so there was an idea to reverse the x and y axes to make the slope between 0 and 1, then use the bresenham then reverse the coordinates.It worked properly :D
 

FAQ: Locating Pixels with Bresenham's line algorithm

1. How does Bresenham's line algorithm work?

Bresenham's line algorithm is a method for determining which pixels to include in a line between two given points on a grid. It works by calculating the slope of the line and then using a decision variable to determine which pixels should be included. The algorithm then adjusts the decision variable as it moves along the line to ensure that the line stays as straight as possible.

2. What is the advantage of using Bresenham's algorithm?

The main advantage of Bresenham's algorithm is its efficiency. Unlike other line-drawing algorithms, it only uses integer calculations and does not require any floating-point operations. This makes it faster and more suitable for use in computer graphics.

3. Can Bresenham's algorithm be used for curves?

No, Bresenham's algorithm is designed specifically for drawing straight lines on a grid. It cannot be used for curves or other non-linear shapes.

4. What are the limitations of Bresenham's algorithm?

One limitation of Bresenham's algorithm is that it can only draw lines at angles that are multiples of 45 degrees. This means that diagonal lines may not appear as smooth as other lines. Another limitation is that it does not take into account the thickness of the line being drawn, so thicker lines may appear jagged.

5. How is Bresenham's algorithm used in computer graphics?

Bresenham's algorithm is commonly used in computer graphics for drawing lines and shapes on a grid. It is often used in applications such as video games, computer-aided design (CAD), and image processing. It is also used in printers and plotters to accurately draw lines and curves on paper.

Similar threads

Replies
4
Views
3K
Replies
1
Views
3K
Replies
14
Views
2K
Replies
11
Views
1K
Replies
2
Views
935
Replies
1
Views
1K
Replies
4
Views
1K
Replies
1
Views
3K
Back
Top