## Direct Method for Line Drawing Algorithm

Direct Method for Line Drawing Algorithm method is the easiest and straightforward method that uses Cartesian *slope-intercept* equation of a line :

y = mx + b –[1]

Here x and y are the coordinates of any point of a line, ‘m’ represents the slope of line and ‘b’ is the y intercept

1. In order to generate all the points of a line segment we need two endpoints of the line segment.

2. Let assume that the coordinates of one endpoint are (x_{1}, y_{1}) and that of second endpoint are (x_{2}, y_{2}).

3. From these four values: x_{1}, y_{1} , x_{2}, y_{2}, we then calculate the value for the slope *m* as:

m = y

_{2}– y_{1}/x_{2}– x_{1}–[2]

4. The value of b can be:

b = y

_{1}– mx_{1}–[3]

5. For any given x interval Δx along a line, we can calculate the corresponding y interval Δy by substituting the value of x in eq[1] since the other terms of the line equation m and b are constant and known.

Δy = mΔx

–[4]

6. Similarly, we can get the x interval Δx corresponding to a specified Δy as:

Δx = Δy/m

–[5]

The equations [4] and [5] are used to set the horizontal and vertical deflection voltages in analog device.

7. For lines whose slope magnitude |m|< 1, Δx is set proportional to a small horizontal deflection voltage and the corresponding vertical deflection voltage is then set proportional to Δy (using equation 4).

8. For lines whose slope magnitude |m|> 1, Δy is set proportional to small vertical deflection voltage and the corresponding horizontal voltage is set proportional to Δx (using equation 5).

9. For lines whose slope magnitude |m|=1, Δx = Δy i.e. the horizontal and vertical deflection voltages are equal.

Although this algorithm is simple and easy to implement but it involves floating point computations (multiplication and addition) in every step. It consumes a lot of time.

### Related posts:-

[su_posts template=”templates/list-loop.php” posts_per_page=”3″ taxonomy=”link_category” tax_operator=”NOT IN” order=”

desc”]