Locating Pixels with Bresenham's line algorithm

  • Thread starter Thread starter armin11
  • Start date Start date
  • Tags Tags
    Algorithm Line
Click For Summary
To locate pixels of a line from (0,0) to (-4,-8) using Bresenham's line algorithm, one must first write the line equation in the form y = ax + b. By substituting specific x values into the equation, the corresponding y values can be calculated, rounding to the nearest integer. The algorithm can be challenging with negative slopes, but reversing the x and y axes to create a positive slope allows for successful application of Bresenham's algorithm. After processing the coordinates, they can be reversed back to obtain the correct pixel locations. This method effectively resolves the issue of locating pixels for lines with negative slopes.
armin11
Messages
66
Reaction score
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
I've searched so much and tried every algorithm but couldn't reach a reaspnable solution ?!
 
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.
 
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.
 
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
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K