Locating Pixels with Bresenham's line algorithm

  • Thread starter Thread starter armin11
  • Start date Start date
  • Tags Tags
    Algorithm Line
Click For Summary

Discussion Overview

The discussion revolves around locating pixels for a line drawn from (0,0) to (-4,-8) using Bresenham's line algorithm. Participants explore methods for determining pixel locations, particularly focusing on the challenges posed by negative slopes.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested

Main Points Raised

  • One participant seeks assistance in locating pixels for a specific line using Bresenham's algorithm, indicating difficulty in finding a suitable method.
  • Another participant expresses frustration after attempting various algorithms without success.
  • A suggestion is made to derive the equation of the line and calculate pixel locations by substituting x-values into the equation to find corresponding y-values.
  • One participant challenges the initial question, asserting that the solution lies in applying Bresenham's algorithm directly.
  • A later reply shares a workaround for handling negative slopes by reversing the x and y axes to create a slope between 0 and 1, applying Bresenham's algorithm, and then reversing the coordinates back.

Areas of Agreement / Disagreement

Participants express differing views on the applicability of Bresenham's algorithm for negative slopes, with some proposing alternative methods while others advocate for the direct application of the algorithm.

Contextual Notes

Some assumptions about the applicability of Bresenham's algorithm may be missing, particularly regarding its performance with negative slopes and the implications of coordinate transformations.

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
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 5 ·
Replies
5
Views
3K