展开全部
中点画线法
void MidPoint_Line(x0, y0, x1, y1, color) i
nt x0, y0, x1, y1, color;
{ int a, b, delta1, delta2, d, x, y;
a=y0-y1; b=x1-x0;
d=2*a+b; delta1=2*a; delta2=2*(a+b);
x=x0; y=y0;putpixel(x, y, color);
while(x<x1) {
if(d<0) { x++; y++; d+=delta2; }
else { x++; d+=delta1; }
putpixel(x, y, color); }}
Bresenham算法
int sign( x)
/*==================================*/
int x;
{
if(x>0)return 1;
if(x==0)return 0;
if(x<0)return -1;
}
/*=======================================================*/
void Generialzed_Integer_Bresenham_Line(x1,y1,x2,y2,color)
int x1,y1,x2,y2,color;
{
int x,y,dx,dy,s1,s2,temp,interchange,e,i;
x=x1;y=y1;
dx=abs(x2-x1);
dy=abs(y2-y1);
s1=x2-x1;
s2=y2-y1;
s1=sign(s1);
s2=sign(s2);
if(dy>dx)
{
temp=dx;
dx=dy;
dy=temp;
interchange=1;
}
else interchange=0;
e=2*dy-dx;
for(i=1;i<=dx;i++)
{
putpixel(x,y,color);
if(e>0)
{
if(interchange==1) x=x+s1;
else y=y+s2;
e=e-2*dx;
}
if(interchange) y=y+s2;
else x=x+s1;
e=e+2*dy;
}
}
void MidPoint_Line(x0, y0, x1, y1, color) i
nt x0, y0, x1, y1, color;
{ int a, b, delta1, delta2, d, x, y;
a=y0-y1; b=x1-x0;
d=2*a+b; delta1=2*a; delta2=2*(a+b);
x=x0; y=y0;putpixel(x, y, color);
while(x<x1) {
if(d<0) { x++; y++; d+=delta2; }
else { x++; d+=delta1; }
putpixel(x, y, color); }}
Bresenham算法
int sign( x)
/*==================================*/
int x;
{
if(x>0)return 1;
if(x==0)return 0;
if(x<0)return -1;
}
/*=======================================================*/
void Generialzed_Integer_Bresenham_Line(x1,y1,x2,y2,color)
int x1,y1,x2,y2,color;
{
int x,y,dx,dy,s1,s2,temp,interchange,e,i;
x=x1;y=y1;
dx=abs(x2-x1);
dy=abs(y2-y1);
s1=x2-x1;
s2=y2-y1;
s1=sign(s1);
s2=sign(s2);
if(dy>dx)
{
temp=dx;
dx=dy;
dy=temp;
interchange=1;
}
else interchange=0;
e=2*dy-dx;
for(i=1;i<=dx;i++)
{
putpixel(x,y,color);
if(e>0)
{
if(interchange==1) x=x+s1;
else y=y+s2;
e=e-2*dx;
}
if(interchange) y=y+s2;
else x=x+s1;
e=e+2*dy;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询