Key point which I mistaken is don't take rounded off value for next iteration. Take original value of y for next iteration, otherwise u ll be in trouble.

Dark Mode

1,049 views

1 vote

According to DDA algorithm,

|dx| = 8, |dy| = 4

since |dx| > |dy|, steps = |dx| = 8

X_{inc }= |dx|/steps = 1, Y_{inc } = |dy|/steps = 0.5.

Algorithm:

for k = 1 to steps:

X_{k+1 }= Y_{k }+ X_{inc}

Y_{k+1} = Y_{k} + Y_{inc}

// plot round(X_{k+1}), round(Y_{k+1})

Since DDA works with integer values only, we need to round the values of coordinates to nearest integer. Consider 0.5 to be rounded to 1.

Thus following the algorithm, we get the first four points as (0, 0), (1, 1), (2, 1), (3, 2).

**Hence option 1.**