Content deleted Content added
No edit summary |
|||
Line 5:
==Algorithm (Naïve Floating-Point Implementation)==
The straightforward DDA algorithm requires a fast floating-point add and round() operation for good performance. Here an example in the [[C programming language]] interpolating a single value <code>x</code> between start and end point:<ref>Code is inspired by Watt 2000, p. 184.</ref>
<code>
Line 50:
==Integer Implementation with seperated Fractional Part==
By splitting the integer and fractional part of all floating-point numbers, the algorithm can get converted to fixed-point arithmetics, so that it achieves good performance on architectures without floating-point support. Now the inner-loop rounding is replaced by a fractional-part overflow handler:
<code>
/*
void
{
int xi =
int xf = -(yb
int mi = (xb
int mi = 2
xi++;▼
▲ for(k=0; k<steps; k++) {
▲ }
}
</code>
==DDAs for line drawing==
The above implementations interpolate only x values and iterate y values. This is a perfect approach when rasterizlng triangles with horizontal lines (two DDAs interpolate x coordinate, colors etc. for the left and right edge, a third DDA interpolates colors etc on the horizontal line inbetween). But when rasterizing lines, then gaps will occur, when abs(mx) < 1. So a line drawing algorithm using DDAs has to check whether abs(mx) < 1, and interpolate y instead of x if required (since my < 1 if mx > 1).
==Performance==
|