多角形を太らせる/痩せさせる

*

交差判定をしていないので、痩せさせる厚さが大きいとアンダーカットが発生することがある

Java風

double thickness = 0.1;//痩せさせる厚さ
//頂点座標 反時計回り
double[] x = {1.7,2,1.9,1.63,1.44,1.62,1.22,1.16,0.84,0.78,0.38,0.56,0.37,0.1,0,0.3,0.37,0.1,0.38,0.56,0.84,0.78,1.22,1.16,1.44,1.62,1.9,1.63};
double[] y = {1,1,1.43,1.3,1.55,1.78,1.97,1.68,1.68,1.97,1.78,1.55,1.3,1.43,1,1,0.7,0.57,0.22,0.45,0.32,0.03,0.03,0.32,0.45,0.22,0.57,0.7};
int n = x.length;
int u = n-1;
double[] vx = new double[n];
double[] vy = new double[n];
double[] rx = new double[n];
double[] ry = new double[n];
double k,kx,ky;
for(int i=0;i<n;i++){
	kx = x[u]-x[i];
	ky = y[u]-y[i];
	k = 1.0/Math.sqrt(kx*kx+ky*ky);
	vx[i] = kx*k;
	vy[i] = ky*k;
	u = i;
}
u = 0;
for(int i=n;i--!=0;){
	k = thickness/(vx[u]*vy[i]-vx[i]*vy[u]);
	rx[i] = (vx[u]-vx[i])*k+x[i];
	ry[i] = (vy[u]-vy[i])*k+y[i];
	u = i;
}
//配列rx,ryに結果が求まる
for(int i=0;i<n;i++) System.out.println(rx[i]+","+ry[i]);
inserted by FC2 system