#include #include //四捨五入を考慮しない場合の直線補間 //dx > dyでかつdx,dyが共に正であること void Interpolate2D_UnRoundOff(int16_t dx,int16_t dy){ int16_t e=0; int16_t x,y; x=0; y=0; while(1){ printf("%d %d\n",x,y); x++; if(x>=dx){ if(y != dy){ y++; } printf("%d %d\n",x,y); return; } e += dy; if (e>=dx){ e -= dx; y++; } } } //四捨五入を考慮した場合の直線補間 //dx > dyでかつdx,dyが共に正であること void Interpolate2D_RoundOff(int16_t dx,int16_t dy){ int16_t e=dx; //初期値を与えるのがポイント int16_t x,y; x=0; y=0; while(1){ printf("%d %d\n",x,y); x++; if(x>=dx){ if(y != dy){ y++; } printf("%d %d\n",x,y); return; } e += 2*dy; if (e>=2*dx){ e -= 2*dx; y++; } } } int main(void){ printf("#interpolate\n"); Interpolate2D_UnRoundOff(10,1); return 0; }