Pergunta

How do I draw a non-orthogonal line?

If we have an orthogonal line it's pretty easy:

Consider X1 = 100, Y1 = 80; And X2=100, Y2 = 185;

So we have something like this for this line.

for(nRow = Y1; nRow < Y2; nRow++)
{
   for(nCol = X1; nCol < X2; nCol++)
   {
     nPixPos = nRow*nEffectiveWidth+nCol*3;

     Image[nPixPos] = 0 ; /// Image -> unsigned char * (BUFFER) || 0 -> Black COLOR
     Image[nPixPos+1] = 0 ;
     Image[nPixPos+2] = 0 ;
  }
}

If I want to draw a non-orthogonal line such as:

X1 = 100 , Y1 = 80 and X2 = 115 , Y2 = 185

How would I go about constructing a loop to draw this line?

Foi útil?

Solução

You have a few algorithms to choose from I suggest Bresenham's algorithm if you don't want anti-aliasing and Xiaolin-Wu's if you do.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top