In DDA, why are lines sampled in unit intervals of x if gradient <= 1

218 views Asked by At

from Wikipedia,

A linear DDA starts by calculating the smaller of dy or dx for a unit increment of the other. A line is then sampled at unit intervals in one coordinate and corresponding integer values nearest the line path are determined for the other coordinate.

Considering a line with a positive slope, if the slope is less than or equal to 1, we sample at unit x intervals (dx=1) [...]

For lines with a slope greater than 1, we reverse the role of x and y i.e. we sample at dy=1 [...]

Similar calculations are carried out to determine pixel positions along a line with a negative slope

  1. How does the slope (positive or negative) affect the algorithm?
  2. why is the gradient being less or equal to 1 important?
1

There are 1 answers

4
Nico Schertler On
  1. If your gradient is negative (in one of the dimensions) and you walk along that direction with unit increments, you have to adapt your loop to count backwards.

  2. If you walk along the wrong dimension (with unit increments), you will end up with gaps on the line. E.g., if you have slope 2 and you walk along the x-direction, only every second row will contain a pixel.