Bresenham high efficiency line algorithm

zhaozj2021-02-11  155

Bresenham high efficiency line algorithm

The algorithm of the drawing is a lot, but it is not easy to do high speed. Slope multiplication is one of the simplest methods, but calculates every point to take a lot of time for multiplication, division operation; the following introduction is the Bresenham's high-efficiency line algorithm, the coordinate calculation of each point is added, The subtraction can be completed. The simplified algorithm is described as follows: Procedure Drawline (X1, Y1, X2, Y2: Integer); VAR X, Y, Deltax, Deltay, Halfx, Errorterm, I: Integer; Begin Deltax: = x2 - x1; Deltay: = Y2 - Y1; HALFX: = (x2 - x1) shr 1; errorterm: = 0; x: = x1; y: = Y1; for i: = 0 to deltax do begin plot (x, y); inc (x ERRORTERM: = Errorterm Deltay; if Errorterm> Halfx The Begin Errorterm: = Errorterm - Deltax; Inc (Y); End; End; End; For easy reading, the above program is simplified. The actual program should be amended to handle DelTax and deltay, if necessary, exchange start, end points, etc. The corrected pseudo-PASCAL algorithm is as follows: Procedure Drawline (x1, y1, x2, y2: integer); VAR X, Y, Deltax, Deltay, Halfcount, ErrorTerm, I, Flag: Integer; Begin Deltax: = x2 - x1; Deltay: = Y2 - Y1;

转载请注明原文地址:https://www.9cbs.com/read-5643.html

New Post(0)