回転変換

void  rot(double *x,double *y,double th){
 double ox = *x;
 double oy = *y;
 *x = ox * cos(th) - oy * sin(th);
 *y = ox * sin(th) + oy * cos(th);
}

描画部

void draw(double th , int xhome , int yhome){
 double x,y,x0,y0,x1,y1,tloop;
 
 GWsetpen(GWC_BLACK,GWL_SOLID,1,GWX_COPYPEN);

 func(&x,&y,0);
 rot(&x,&y,th);
 x0 = xhome + MAG * x;
 y0 = yhome - MAG * y;
   
 for(tloop = 0 ; tloop <= 360.0 / 180.0 * 3.141592 ; tloop += 1.0 / 180.0 * 3.141592){
   func(&x,&y,tloop);
   rot(&x,&y,th);
   x1 = xhome + MAG * x;
   y1 = yhome - MAG * y;
       
   GWline(x0,y0,x1,y1);
       
   x0 = x1;y0 = y1;
 }
}

角度変更反復部

for(th = 0 ; th <= 360.0 / 180.0 * 3.141592 ; th += 120.0 / 180.0 * 3.141592){
 draw(th,xhome,yhome);
}

タグ:

c
最終更新:2007年01月10日 14:29