Thread: DDA algo logic

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    113

    DDA algo logic

    I have spend whole day understanding the logic behind digital differential analyser algo(for drawing line).Please make me understand this algo.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What are you expecting us to say that inumerable web pages haven't said already?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    The whole point is to get rid of the need to perform slow calculations such as using multiply or divide, and replace them with fixed sized steps, which we can simply add on every step and will obviously be much faster. However, this isn't quite enough. With this alone, the line will usually drift away from the exact line should be.
    So what we also do is work out how often we'll need to adjust the line to compensate. We'll only ever need to compensate by 1 pixel, because we wont let ourselves get any furthur out than that thanks to our initial calculations. As we go along, when we've acculumated enough error for our line to otherwise drift away from the true line, then we add 1 to bring it right again.

    For example, lets say our line needs to go down by 100 pixels, and across by 228 pixels.
    As you can see, our constant step size will be 2 pixels, and stepping by that amount each time will head in the correct general direction. Then for every 100 pixels we need to add another 28.
    So each step we add 2 to the line, and also add 28 to another variable (err). If err reaches 100, then we adjust the line by adding 1, and subtract 100 from err.
    Over the course of traversing the line, we will have added 28*100 = 2800 to err. It will have gone across an extra pixel for each 100 we added, so over the length of the line it will have added an extra 28 pixels. Our fixed size step gave us 2*100 pixels, so we stepped a total of 228 pixels, exactly as desired, in a smooth manner, and no divide per step.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  2. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 10:58 PM
  3. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  4. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 08:10 PM