为什么这个画线算法有缺陷
void LCD_DrawLine(unsigned int x1, unsignedint y1, unsignedint x2, unsignedint y2,unsignedint color){
unsignedint x, y, t;
if((x1 == x2) && (y1 == y2))
LCD_DrawPoint(x1, y1,color);
else if( (abs(y2 - y1))> (abs(x2 - x1)))
{
if(y1 > y2)
{
t = y1;
y1 = y2;
y2 = t;
t = x1;
x1 = x2;
x2 = t;
}
for(y = y1; y <= y2; y ++)
{
x = (y - y1) * (x2 - x1) / (y2 - y1) + x1;//为什么这里会有不少x丢失
LCD_DrawPoint(x, y,color);
}
}
else
{
if(x1 > x2)
{
t = y1;
y1 = y2;
y2 = t;
t = x1;
x1 = x2;
x2 = t;
}
for(x = x1; x <= x2; x ++)
{
y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
LCD_DrawPoint(x, y,color);
}
}
}
难道没人知道吗 画线里面一般采用,布兰森汉姆(Bresenham)算法画线,可以看一下 奥奥,谢了啊
页:
[1]