Direct Method or Polynomial Method for Line Drawing

By | March 8, 2022

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 (x1, y1) and that of second endpoint are  (x2, y2).

Direct Method for Line Drawing Algorithm

3. From these four values: x1, y1 , x2, y2, we then calculate the value for the slope m as:

m = y2 – y1/x2 – x1  –[2]

4. The value of b can be:

b = y1 – mx1  –[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:-