How to scan convert right edges and slopes less than one?
Posted
by Zachary
on Stack Overflow
See other posts from Stack Overflow
or by Zachary
Published on 2010-03-22T03:24:00Z
Indexed on
2010/03/22
3:31 UTC
Read the original article
Hit count: 363
graphics
|scan-conversion
I'm writing a program which will use scan conversion on triangles to fill in the pixels contained within the triangle.
One thing that has me confused is how to determine the x increment for the right edge of the triangle, or for slopes less than or equal to one.
Here is the code I have to handle left edges with a slope greater than one (obtained from Computer Graphics: Principles and Practice second edition):
for(y=ymin;y<=ymax;y++)
{
edge.increment+=edge.numerator;
if(edge.increment>edge.denominator)
{
edge.x++;
edge.increment -= edge.denominator;
}
}
The numerator is set from (xMax-xMin), and the denominator is set from (yMax-yMin)...which makes sense as it represents the slope of the line. As you move up the scan lines (represented by the y values). X is incremented by 1/(denomniator/numerator) ...which results in x having a whole part and a fractional part.
If the fractional part is greater than one, then the x value has to be incremented by 1 (as shown in edge.increment>edge.denominator).
This works fine for any left handed lines with a slope greater than one, but I'm having trouble generalizing it for any edge, and google-ing has proved fruitless.
Does anyone know the algorithm for that?
© Stack Overflow or respective owner