简单DDA算法

来源:互联网 发布:tvb视频软件 编辑:程序博客网 时间:2024/06/14 07:48

原理

dydx= 或者ΔyΔx=y2y1x2x1

yi+1=yi+Δy
yi+1=yi+y2y1x2x1Δx

代码

void DDALine(int x0,int y0,int x1,int y1){    HWND myconsole = GetConsoleWindow();    HDC mydc = GetDC(myconsole);    COLORREF COLOR= RGB(255,0,0);    int dx,dy,epsl,k;    float x,y,xIncre,yIncre;    dx=x1-x0;    dy=y1-y0;    x=x0;    y=y0;    if(abs(dx)>abs(dy)) epsl=abs(dx);    else epsl=abs(dy);    xIncre=(float)dx/(float)epsl;    yIncre=(float)dy/(float)epsl;    for(k=0;k<=epsl;k++){        SetPixel(mydc,int(x+0.5),int(y+0.5),COLOR);        x+=xIncre;        y+=yIncre;    }    ReleaseDC(myconsole, mydc);    cin.ignore();}




原创粉丝点击