code


DDA Algorithm:

  1. Calculate the slope (m) = $\dfrac{y_2-y_1}{x_2-x_1}$

  2. Calculate $∆x = x_2-x_1$ and $∆y = y_2-y_1$

  3. If $|∆x|>=|∆y|$

then assign $∆x$ = 1

$x_{i+1} = x_i + ∆x$

$∴ x_{i+1}= x_i + 1$


$y_{i+1} = y_i + ∆y = y_i + m∆x$

$∴y_{i+1}=y_i+m$

If $|∆x|<|∆y|$

then assign $∆y$ = 1

$x_{i+1} = x_i + ∆x = x_i + \dfrac{∆y}{m}$

$∴ x_{i+1}= x_i + \dfrac{1}{m}$


 $y_{i+1}= y_i + ∆y$

$∴y_{i+1}= y_i + 1$

Bresenham’s Algorithm:

  1. Calculate the slope (m) = $\dfrac{y_2-y_1}{x_2-x_1}$

  2. Calculate the decision parameter $P_o$

$P_0 = 2dy-dx$

If $m <1$

If $P<0$

$x_{i+1}= x_i + 1$

$y_{i+1}=y_i$

$P_{i+1}=P_i+2dy$

If $P>=0$

$x_{i+1}= x_i + 1$

$y_{i+1}=y_i+1$

$P_{i+1}=P_i+2dy-2dx$


If $m >= 1$

If $P<0$

$x_{i+1}= x_i$

$y_{i+1}=y_i+1$

$P_{i+1}=P_i+2dx$

If $P>=0$

$x_{i+1}= x_i + 1$

$y_{i+1}=y_i+1$

$P_{i+1}=P_i+2dx-2dy$


Midpoint Circle Drawing Algorithm:

Circle Equation:

$x^2+y^2=r^2$

$x^2+y^2-r^2=0$

$(x+1)^2+(y-\dfrac{1}{2})^2-r^2=d$

$x=0,y=r$

$1+(r-\dfrac{1}{2})^2-r^2=d$

$1+r^2-r+\dfrac{1}{4}-r^2=d$

$1.25-r=d$

Untitled

This Algorithm uses eight ways symmetric property of Circle.

It plots $\dfrac{1}{8}^{th}$ part of the circle from 90° to 45°.

To in draw this arc we need to move along x-direction in every step and need to use the decision parameter to determine which y-position is closer to the actual path.