Locating Pixels with Bresenham's line algorithm

  • Thread starter Thread starter armin11
  • Start date Start date
  • Tags Tags
    Algorithm Line
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 3K views
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