200 likes | 311 Views
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES. LINE DRAWING TO DRAW LINE FROM (X 1 Y 1 ) TO (X 2 Y 2 ). (x 2 y 2 ). (x 1 y 1 ). RASTER SCREEN. (x 2 y 2 ). (x 1 y 1 ). DIGITAL DIFFERENTIAL ANALYZER (DDA). y = m x + b m = (y 2 - y 1 ) / (x 2 - x 1 ) = y / x = dely / delx
E N D
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES • LINE DRAWING • TO DRAW LINE FROM (X1 Y1) TO (X2 Y2) (x2 y2) (x1y1)
RASTER SCREEN (x2 y2) (x1 y1)
DIGITAL DIFFERENTIAL ANALYZER (DDA) • y = m x + b • m = (y2 - y1) / (x2 - x1)= y / x = dely / delx • xk+1 = xk + delxyk+1 = yk + dely • = ?????
TWO ALTERNATIVES • = 1 / max [(x2-x1), (y2 - y1)] (BOOK) • = 1 / 2 K WHERE K IS SUCH THAT2K-1 < (max [(x2-x1), (y2 - y1)]) 2K
SIMPLE DDA delx = x2 - x1; dely = y2 - y1; steps = abs(dely); if abs (delx) > abs (dely) then steps = abs(delx); xinc = delx / steps; yinc = dely / steps; x = x1; y = y1; drawpixel (round(x), round(y)) for k = 1 to steps do begin x = x + xinc; y = y + yinc; drawpixel (round(x), round(y)) end end
BRESENHAM’S ALGO • WHICH PIXEL NEXT ?? ? 2 (xk yk) ? 1
BRESENHAM’S ALGO (contd) • Deviations from the specified line path • d1 = y - yk = m (xk + 1) + b - yk • d2 = yk + 1 -y = yk + 1 - m (xk + 1) - b • d1 - d2 = 2 m (xk + 1) - 2yk + 2b -1 • m = (y / x) • pk = x (d1 - d2) = 2y . xk - 2x . yk + c
Pk = error at beginning of next pixel If (at end of iteration k) true-line is below centre of pixel (pk < 0), draw pixel 1 else draw pixel 2 (in iteration k+1) 2 1
Brezenham’s algo (contd) • pk+1 - pk = 2 y (xk+1 -xk) - 2x (yk+1 -yk) = 2 y - 2x (yk+1 -yk) • For pixel 1: = 2 y • For pixel 2: = 2 y - 2x • Hence if pk < 0, choose pixel 1 in iteration k+1, pk+1 = pk + 2 y • else choose pixel 2 in iteration k+1, pk+1 = pk +2 y - 2 x • Initial p0 = 2 y - x
Brezenham’s algo (contd) pk + m - 1 pk + m pk = p0 = m - 0.5
Circle Generation • (x - a)2 + (y - b)2 = r2 • OR x = a + r cos ; y = b + r sin • (Fixed angular step size with lines between them) • (Step Size = 1/r) • OR m = dy / dx = - (x - a) / (y - b) • USE DDA with m as above
MIDPOINT CIRCLE ALGO Next midpoint ?? 1 yk Yk - 1 ?? 2 xk xk + 1
MIDPOINT CIRCLE • f (x, y) = x2 + y2 - r2 • pk = (xk + 1)2 + (yk - 0.5)2 - r2 (error at next midpoint) • If pk < 0 then Pixel 1 Else Pixel 2 (is closer to circle in iteration k+1) • pk+1 = [(xk + 1) + 1]2 + (yk+1 - 0.5)2 - r2 • pk+1 = pk + 2 (xk + 1) + (yk+12 - yk2) - (yk+1 -yk) + 1
MID POINT CIRCLE (contd) • Pk+1 - pk = 2 xk+1 + 1 OR = 2 xk+1 + 1 - 2yk+1 • p0 = 5/4 - r (PLEASE DERIVE) • INITIAL POINT = (0, r) • GET ONE POINT AND DUPLICATE IN 8 OCTANTS
ELLIPSE DRAWING • SLOPE BASED (DDA) • MIDPOINT ALGO • [(x - a) / rx]2 + [(y - b) / ry]2 = 1 • f (x, y) = (x - a)2 ry2 + (y - b)2 rx2 -rx2 ry2 • dy / dx = ???? • If f(x, y) < 0, point is inside the ellipse
MIDPOINT ELLIPSE (contd) • Where slope < 1, xk+1 = xk + 1 • Where slope > 1, yk+1 = yk - 1 • pk = ???? • Pk+1 - pk = ???? (For Regions 1 and 2)
OTHER CURVES • FOR IMPLICIT CURVES F (X, Y) = 0, DEVELOP MIDPOINT ALGO (eg, hyperbola, parabola)
OTHER CURVES • FOR EXPLICIT CURVES Y = F(X), OR PARAMETRIC CURVES - APPROXIMATE WITH STRAIGHT LINE SEGMENTS • Generate points at constant parameter values • Join them by straight lines • Closer points for larger curvatures
ADDRESSING PIXELS • BY PIXEL CENTERS • BY GRID OF PIXEL BOUNDARY LINES (H & V) • PREFERRED, AS • NO HALF INTEGER BOUNDARIES • PRECISE OBJECT REPRESENTATIONS • CONVENIENT IN RASTER ALGOS
SIZE OF OBJECTS • RECTANGLE (0, 0) --- (4, 3) ? ? ? ? (4, 3) ? ? ? (0, 0)