himanshu219
himanshu219

Reputation: 664

Bresenham's algorithm

How to find the decision parameter for drawing different functions like parabola, sine curve, bell curve? Please tell me about the approach why do we sometimes multiply by constant? For Example

  1. in case of ellipse, p = a^2(d1 - d2),p = b^2(d1 - d2) for upper and lower half region
    respectively where a, b constants
  2. in case of line, p = deltax(d1 - d2) where p is decision parameter d1,d2 are
    distances,deltax is constant and is equal to xend - xstart

why not only take (d1 -d2) as parameter

Upvotes: 1

Views: 1160

Answers (1)

chux
chux

Reputation: 153367

Bresenham's algorithm as stated by the OP is a bit amiss, but I assume the following.

The decision parameter could adjust d1 - d2 and not scale by some constant as you suggest were it not for the initialization of the decision parameter. It is not generally scalable by that constant.

// code from http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
plotLine(x0,y0, x1,y1)
  dx=x1-x0
  dy=y1-y0

  D = 2*dy - dx   // Not scalable by 2
  plot(x0,y0)
  y=y0

  for x from x0+1 to x1
    if D > 0
      y = y+1
      plot(x,y)
      D = D + (2*dy-2*dx)  // Scalable by 2
    else
      plot(x,y)
      D = D + (2*dy)  // Scalable by 2

Upvotes: 1

Related Questions