CGMM | DDA Algorithm | Exp 2

SolForEve-Solutions-for-everyone-cgmm-dda-algorithm

Digital Differential Analyzer Algorithm

In any 2-Dimensional plane if we connect two points (x1, y1) and (x2, y2), we get a line segment. But in the case of computer graphics we can not directly join any two coordinate points, for that we should calculate intermediate point’s coordinate and put a pixel for each intermediate point, of the desired color with help of functions like putpixel(x, y, K)
So, to calculate intermediate point we have can use a basic algorithm called DDA(Digital differential analyzer) line generating algorithm.

Working

1. Get the end coordinates of the line i.e. A(x1, y1) & B(x2, y2).
2. Calculate slope (m).

m = (y2 - y1) / (x2 - x1)
3. Now check slope.
    Initially x = x1 & y = y1.
    If m<1, 

x = x+1                                                                                                              y = y + m 
   If m >1,

x = (1 / m) + x                                                                                                      y = y + 1
  And if m = 0, 

x = x +1                                                                                                              y = y + 1


Problem Statement

How Digital Differential Analyzer (DDA) is used for linear interpolation of variables over an interval between start and end point. 

No comments:

Powered by Blogger.