It refers to a line segment, which is a portion of
straight line that extends indefinitely in opposite
directions. The line equation y = mx + c. cannot be applied for horizontal, vertical and diagonal lines. (where |m| = 1) Calculate m = (y2’ – y1’) / (x2’ – x1’) and c = y1’ - mx1’. Then calculate corresponding values starting from (x1, y1) up to (x2, y2). SCAN CONVERTING A LINE Scan converting a point
In first approach point
(x, y) is scan converted to (x’, y’) where x’ and y’ are real part of x and y i.e. Floor(x) and Floor(y).
E.g. point P1 (1.7, 0.8)
is represented by pixel (1, 0). Points P2 (2.2, 1.3) and P3 (2.8, 1.9) are both represented by pixel (2, 1). Scan converting a point In the second approach (x, y) is scan converted by making x’ = Floor(x + 0.5) and y’ = Floor(y + 0.5) This places the origin of coordinate at center of pixel (0, 0). All points within x’ – 0.5 ≤ x ≤ x’ + 0.5 (same for y also) are mapped to pixel (x’, y’). i.e. P1 and P2 both represented by (2, 1), whereas point P3 is represented by pixel (3, 2). If the slope is >= 1, DDA Line sample at unit y interval Drawing Algorithm (dy = 1), and compute •The Digital Differential each successive y values Analyzer (DDA) is a scan- conversion line drawing Xk+1 = xk + 1/m algorithm, based on calculating either dx or dy. •Consider line with positive Draw line using this slope. algorithm between •If the slope is <= 1, sample at points (12, 15) and (30, unit x interval (dx = 1), and 25) compute each successive y values. Yk+1 = yk + m • It scan converts lines by using only integer addition, subtraction, multiplication by 2 (arithmetic shift operation). • Vertical axis is the scan- line position, horizontal line is the pixel columns. • Consider 0 <m <1. • Pixel position is determined by sampling at unit x- interval. • It chooses the y value closest to the line path. After k step, at sampling position Xk + 1, the lines d1, d2 are calculated as y = m(xk + 1) +b Then, d1 = y – yk = m(xk + 1) +b – yk And d2 = (yk + 1) -y = yk + 1 - m(xk + 1) -b Then d1 – d2 = 2m(xk + 1) – 2yk + 2b -1 The decision parameter for k step pk = dx (d1 – d2) = 2dy . xk -2dx . yk + c Where, c = 2dy + dx(2b – 1) Pk+1 = dx (d1 – d2) = 2dy . Xk+1 -2dx . Yk+1 + c Then, Pk+1 – pk = 2dy(xk+1 – xk) – 2dx(yk+1 – yk) But Xk+1 = xk + 1 Pk+1 = pk + 2dy – 2dx (yk+1 – yk) P0 = 2dy –dx, yk+1 – yk = 1 or 0depending on sign of pk P0 = 2dy – dx
If pk < 0, the next point to plot is (xk + 1, yk + 1)
and pk+1 = pk + 2dy
Otherwise, the next point to plot is
(xk + 1, yk + 1) and pk+1 = pk + 2dy – 2dx Draw line between (20, 10) and (30, 18). Using DDA algorithm Using Bresenham’s algorithm K pk Xk+1, yk+1