高分!!!急~~~~一道计算机图形学算法的问题。。
来源:百度知道 编辑:UC知道 时间:2024/08/22 00:57:31
请给这个算法添加函数使它能实现,要详细的:
void MidBresenhamLine(int x0,int y0,int x1,int y1,int color)
{
int dx,dy,d,UpIncre,DownIncre,x,y;
if(x0>x1)
{
x=x1;x1=x0;x0=x;
y=y1;y1=y0;y0=y;
}
x=x0;y=y0;
dx=x1-x0;
dy=y1-y0;
d=dx-2*dy;
UpIncre=2*dx-2*dy;
DownIncre=-2*dy;
while(x<=x1)
{
putpixel(x,y,color);
x++;
if(d<0)
{
y++;
d+=UpIncre;
}
else
d+=DownIncre;
}
}
谢谢啦
void MidBresenhamLine(int x0,int y0,int x1,int y1,int color)
{
int dx,dy,d,UpIncre,DownIncre,x,y;
if(x0>x1)
{
x=x1;x1=x0;x0=x;
y=y1;y1=y0;y0=y;
}
x=x0;y=y0;
dx=x1-x0;
dy=y1-y0;
d=dx-2*dy;
UpIncre=2*dx-2*dy;
DownIncre=-2*dy;
while(x<=x1)
{
putpixel(x,y,color);
x++;
if(d<0)
{
y++;
d+=UpIncre;
}
else
d+=DownIncre;
}
}
谢谢啦
#include <conio.h>
#include <stdio.h>
#include <graphics.h>
void MidBresenhamLine(int x0,int y0,int x1,int y1,int color);
int main(void)
{
int GraphDriver;
int GraphMode;
GraphDriver = DETECT;
initgraph(&GraphDriver, &GraphMode, "");
MidBresenhamLine(10, 10, 300, 300, 12);
getch();
closegraph();
return 0;
}
void MidBresenhamLine(int x0,int y0,int x1,int y1,int color)
{
int dx,dy,d,UpIncre,DownIncre,x,y;
if(x0>x1)
{
x=x1;x1=x0;x0=x;
y=y1;y1=y0;y0=y;
}
x=x0;y=y0;
dx=x1-x0;
dy=y1-y0;
d=dx-2*dy;
UpIncre=2*dx-2*dy;
DownIncre=-2*dy;
while(x<=x1)
{
putpixel(x,y,color);
x++;
if(d<0)
{
y++;
d+=UpIncre;
}
else
d+=DownIncre;
}
}
好像是图形的坐标没定义好
这不是画任何直线的算法吗?添加什么函数?