C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
DDA AlgorithmDDA stands for Digital Differential Analyzer. It is an incremental method of scan conversion of line. In this method calculation is performed at each step but by using results of previous steps. Suppose at step i, the pixels is (xi,yi) The line of equation for step i Next value will be Case1: When |M|<1 then (assume that x1<>2) Case2: When |M|<1 then (assume that y1<>2) Advantage:
Disadvantage:
DDA Algorithm:Step1: Start Algorithm Step2: Declare x1,y1,x2,y2,dx,dy,x,y as integer variables. Step3: Enter value of x1,y1,x2,y2. Step4: Calculate dx = x2-x1 Step5: Calculate dy = y2-y1 Step6: If ABS (dx) > ABS (dy) Step7: xinc=dx/step Step8: Set pixel (x, y) Step9: x = x + xinc Step10: Repeat step 9 until x = x2 Step11: End Algorithm Example: If a line is drawn from (2, 3) to (6, 15) with use of DDA. How many points will needed to generate such line? Solution: P1 (2,3) P11 (6,15) x1=2 For calculating next value of x takes x = x + Program to implement DDA Line Drawing Algorithm:#include Output: Symmetrical DDA:The Digital Differential Analyzer (DDA) generates lines from their differential equations. The equation of a straight line is The DDA works on the principle that we simultaneously increment x and y by small steps proportional to the first derivatives of x and y. In this case of a straight line, the first derivatives are constant and are proportional to ∆x and ∆y . Therefore, we could generate a line by incrementing x and y by ϵ ∆x and ϵ ∆y, where ϵ is some small quantity. There are two ways to generate points 1. By rounding to the nearest integer after each incremental step, after rounding we display dots at the resultant x and y. 2. An alternative to rounding the use of arithmetic overflow: x and y are kept in registers that have two parts, integer and fractional. The incrementing values, which are both less than unity, are repeatedly added to the fractional parts and whenever the results overflows, the corresponding integer part is incremented. The integer parts of the x and y registers are used in plotting the line. In the case of the symmetrical DDA, we choose ε=2-n,where 2n-1≤max (|∆x|,|∆y|)<2π A line drawn with the symmetrical DDA is shown in fig: Example: If a line is drawn from (0, 0) to (10, 5) with a symmetrical DDA 1. How many iterations are performed? 2. How many different points will be generated? Solutions: Given: P1 (0,0) P2 (10,5) P1 (0,0) will be considered starting points Following Figure show line plotted using these points.
Next TopicBresenham's Line Algorithm
|