3匹の子ブタと円の周りの長さ



これらの図を描いたjavaプログラム(アプレットの紹介)
mport java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
public class ennsyuu extends Applet {
private static final long serialVersionUID = 1L;
/**
* This is the default constructor
*/
public ennsyuu() {
super();
}
int wid=4;
int kosu=100;//直径に並ぶレンガ数
int rengaSu;
/**
* This method initializes this
*
* @return void
*/
public void init() {
this.setSize(658, 776);
keisan(wid ,kosu);
}
int[][] itiX=new int[1000][4];
int[][] itiY=new int[1000][4];
int sX;
int sY;
public void keisan(int w,int k){
sX = (this.getSize().width)/2;
sY = (this.getSize().height)/2;
double r = wid * kosu / 2;//これは良い
itiX[0][0] =sX;
itiY[0][0] =sY+(int)r;
//まず、円周にいくつレンガが並ぶか計算 (直径の個数×3.14)の整数値
rengaSu =(int)( k * Math.PI);
double kaku = Math.acos( ( r*r + r*r - wid*wid) /( 2*r*r) );
for( int i=0;i< rengaSu ;i++){
double ka = kaku * i;
double ka2= kaku * (i+1);
//位置を当てはめる
itiX[i][0] =sX +(int)( (double)r * Math.cos(-ka) );
itiY[i][0] =sY +(int)( (double)r * Math.sin(-ka) );
itiX[i][1] =sX +(int)( (double)r * Math.cos(-ka2) );
itiY[i][1] =sY +(int)( (double)r * Math.sin(-ka2) );
int xp=itiY[i][0]-itiY[i][1] ;
int yp=itiX[i][0]-itiX[i][1] ;
itiX[i][2] =itiX[i][1]+xp;
itiY[i][2] =itiY[i][1]-yp;
itiX[i][3] =itiX[i][0]+xp;
itiY[i][3] =itiY[i][0]-yp;
}
}
public void paint(Graphics g ){
int x=(this.getSize().width)/2;
int y=(this.getSize().height)/2;
int r=wid*kosu/2;

for(int i=0;i<rengaSu;i++){
g.setColor(Color.YELLOW);
g.fillPolygon( itiX[i],itiY[i] ,4 );
g.setColor(Color.BLACK);
g.drawPolygon( itiX[i],itiY[i] ,4 );
}
g.fillOval(sX-1, sY-1, 2, 2);
for( int i=0;i<kosu;i++){
int xx=sX-kosu*wid/2 + i*wid;
int yy=sY+kosu*wid/2+wid+10;
g.setColor(Color.YELLOW);
g.fillRect(xx, yy, wid, wid);
g.setColor(Color.BLACK);
g.drawRect(xx, yy, wid, wid);
}
g.drawOval(x-r, y-r, r*2, r*2);
}
} // @jve:decl-index=0:visual-constraint="10,10"