数值微分(DDA法 DDA画线算法程序 void LineDDa (int xo, int yo, int x,,int y,, int color)/*假定x0(x1,-1<=k<=1米 int x: float dx, dy, y, k x-Ⅹ dy k=-dy/dx for(x=x: X< x++) I Putpixel(x, int(y+0. 5) 而=十=2
数值微分(DDA)法 • DDA画线算法程序 • void LineDDA(int x0 ,int y0 ,int x1 ,int y1 ,int color) /* 假定x0 <x1 ,-1<=k<=1 */ • { int x; • float dx, dy, y, k; • dx= x1 -x0 ; • dy=y1 -y0 ; • k=dy/dx; • y=y0 ; • for(x=x0 ; x<= x1 , x++) • { Putpixel(x, int(y+0.5), color); • y+=k; • } • }
数值微分(DDA法 ·举例:用DDA方法扫描转换连接两点PO(O,0) 和P1(5,2)的直线段。 xint(y+0.5)y+0.5 Line:P0(0,0)-P1(5,2) 00 0 0.4+0.5 0.8+0.5 1.2+0.5 1.6+0.5
数值微分(DDA)法 • 举例:用DDA方法扫描转换连接两点P0(0,0) 和P1(5,2)的直线段。 x int(y+0.5) y+0.5 0 0 0 1 0 0.4+0.5 2 1 0.8+0.5 3 1 1.2+0.5 4 2 1.6+0.5
数值微分(DDA法 ·举例:用DDA方法扫描转换连接两点PO(O,0) 和P1(5,2)的直线段。 xint(y+0.5)y+0.5 Line:P0(0,0)-P1(5,2) 00 0 0 0.4+0.5 0.8+0.5 1.2+0.5 1.6+0.5
数值微分(DDA)法 • 举例:用DDA方法扫描转换连接两点P0(0,0) 和P1(5,2)的直线段。 x int(y+0.5) y+0.5 0 0 0 1 0 0.4+0.5 2 1 0.8+0.5 3 1 1.2+0.5 4 2 1.6+0.5
数值微分(DDA法 ·举例:用DDA方法扫描转换连接两点PO(O,0) 和P1(5,2)的直线段。 xint(y+0.5)y+0.5 Line:P0(0,0)-P1(5,2) 00 0 0.4+0.5 0.8+0.5 1.2+0.5 1.6+0.5
数值微分(DDA)法 • 举例:用DDA方法扫描转换连接两点P0(0,0) 和P1(5,2)的直线段。 x int(y+0.5) y+0.5 0 0 0 1 0 0.4+0.5 2 1 0.8+0.5 3 1 1.2+0.5 4 2 1.6+0.5
数值微分(DDA法 ·举例:用DDA方法扫描转换连接两点PO(O,0) 和P1(5,2)的直线段。 xint(y+0.5)y+0.5 Line:P0(0,0)-P1(5,2) 00 0 0.4+0.5 0.8+0.5 3 1.2+0.5 1.6+0.5
数值微分(DDA)法 • 举例:用DDA方法扫描转换连接两点P0(0,0) 和P1(5,2)的直线段。 x int(y+0.5) y+0.5 0 0 0 1 0 0.4+0.5 2 1 0.8+0.5 3 1 1.2+0.5 4 2 1.6+0.5