Switch to full style
C++ code examples
Post a reply

DDA Line Drawing Algorithm

Sat Jul 21, 2012 12:08 am

DDA Line Drawing Algorithm implementation on MFC,
Code:

void DrawByDDA
(HDC hdc,int xs,int ys,int xe,int ye,COLORREF color)
{
int dx=xe-xs;
int dy=ye-ys;
SetPixel(hdc,xs,ys,color);
if(
abs(dx)>=abs(dy))
{
int x=xs,xincdx>0?1:-1;
double y=ys,yinc=(double)dy/dx*xinc;
while(
x!=xe)
{
x+=xinc;
y+=yinc;
SetPixel(hdc,x,round(y),color);
}
}
 
else
{
int y=ys,yincdy>0?1:-1;
double x=xs,xinc=(double)dx/dy*yinc;
while(
y!=ye)
{
x+=xinc;
y+=yinc;
SetPixel(hdc,round(x),y,color);
}
}




Post a reply
  Related Posts  to : DDA Line Drawing Algorithm
 Bresenham (midpoint) algorithm (integer DDA) drawing line     -  
 Line Midpoint algorithm (J2ME)     -  
 Circle direct drawing algorithm     -  
 Circle drawing using Polar based algorithm with C++     -  
 Reading a File Line by Line in php     -  
 Line Translation 2D     -  
 Line Rotation 2D     -  
 start a new line in html     -  
 Line Styles in java     -  
 getting a full line input     -  

Topic Tags

C++ Graphics