简体   繁体   中英

How do I draw line (slanting line)?

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?

如果您不想使用抗锯齿,则可以选择Bresenham的算法,如果需要,可以选择Xiaolin-Wu的 算法

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM