Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The image is stored row major, so you want to go down each row. The equation of a line is y=m*x+b, but we need to invert it. x = y/m-b/m.

if(m > 0)
{
    for(int y = 0; y<MIN(b,rows); ++y)
    {
        for(int x = 0; x < MIN(cols, (y-b)/m); ++x)
        {
            //Do Stuff Here
        }
    }
}
else if(m == 0) //Trivial case
else
{
    for(int y = 0; y<MIN(b, rows); ++y)
    {
        for(int x = MAX(0, (y-b)/m); x<cols; ++x)
        {
            //Do Stuff Here
        }
    }
}

Note: This assumes your equation is in image space, which has +y as the bottom of the image.

Can someone else double check this? I don't have a compiler handy.