//---------------------------------------------- //3次Spline補間 public void drawSpline(Graphics g){ int X0 = 0,Y0 = 0; int data_count_low = 0;//データ個数 int data_count_high = 0;//データ個数 //入力データのx値(座標値ではない) double[] dataX_low = new double[7]; //入力データのy値(座標値ではない) double[] dataY_low = new double[7]; //入力データのx値(座標値ではない) double[] dataX_high = new double[5]; //入力データのy値(座標値ではない) double[] dataY_high = new double[5]; int i; double x,y,yy0,yy1,yy2,yy3; double[] h_low = new double[7]; //間隔 double[] dif1_low = new double[7]; //一次微分 double[] dif2_low = new double[7]; //二次微分 double[] h_high = new double[5]; //間隔 double[] dif1_high = new double[5]; //一次微分 double[] dif2_high = new double[5]; //二次微分 // double xx; double yy; int int_x; int int_y; //顔下半分 for (int f = 2;f <= 8;f++){ int_x = out_line_x[f]; int_y = out_line_y[f]; xx=(int_x-X0)/10.0; yy=(int_y-Y0)/10.0; dataX_low[data_count_low]=xx; dataY_low[data_count_low]=yy; data_count_low++; } //顔上半分 int_x = out_line_x[2]; int_y = out_line_y[2]; xx=(int_x-X0)/10.0; yy=(int_y-Y0)/10.0; dataX_high[data_count_high]=xx; dataY_high[data_count_high]=yy; data_count_high++; int_x = out_line_x[1]; int_y = out_line_y[1]; xx=(int_x-X0)/10.0; yy=(int_y-Y0)/10.0; dataX_high[data_count_high]=xx; dataY_high[data_count_high]=yy; data_count_high++; int_x = out_line_x[0]; int_y = out_line_y[0]; xx=(int_x-X0)/10.0; yy=(int_y-Y0)/10.0; dataX_high[data_count_high]=xx; dataY_high[data_count_high]=yy; data_count_high++; int_x = out_line_x[9]; int_y = out_line_y[9]; xx=(int_x-X0)/10.0; yy=(int_y-Y0)/10.0; dataX_high[data_count_high]=xx; dataY_high[data_count_high]=yy; data_count_high++; int_x = out_line_x[8]; int_y = out_line_y[8]; xx=(int_x-X0)/10.0; yy=(int_y-Y0)/10.0; dataX_high[data_count_high]=xx; dataY_high[data_count_high]=yy; data_count_high++; // //------------------------------------------------- //顔の下半分 h_low[0]=0.0; dif2_low[0]=0.0; dif2_low[data_count_low-1]=0.0; for(i=1;i<data_count_low;i++){ h_low[i]=dataX_low[i]-dataX_low[i-1]; //間隔を計算 dif1_low[i]=(dataY_low[i]-dataY_low[i-1])/h_low[i]; //一次微分を計算 } for(i=1;i<data_count_low - 1;i++){ //二次微分を計算 dif2_low[i]=(dif1_low[i+1]-dif1_low[i])/(dataX_low[i+1]-dataX_low[i-1]); } i=1; for(x = dataX_low[0];x < dataX_low[data_count_low - 1];x+=0.01){ if(x < dataX_low[i]){ yy0=dif2_low[i-1]/(6*h_low[i])*(dataX_low[i]-x)*(dataX_low[i]-x)*(dataX_low[i]-x); //第1項 yy1=dif2_low[i]/(6*h_low[i])*(x-dataX_low[i-1])*(x-dataX_low[i-1])*(x-dataX_low[i-1]); //第2項 yy2=(dataY_low[i-1]/h_low[i]-h_low[i]*dif2_low[i-1]/6)*(dataX_low[i]-x); //第3項 yy3=(dataY_low[i]/h_low[i]-h_low[i]*dif2_low[i]/6)*(x-dataX_low[i-1]); //第4項 y=(yy0+yy1+yy2+yy3); g.drawRect(X0+(int)(10*x),Y0+(int)(10*(y)),0,0); } else i++; } //------------------------------------------------- //顔の下半分 h_high[0]=0.0; dif2_high[0]=0.0; dif2_high[data_count_high-1]=0.0; for(i=1;i<data_count_high;i++){ h_high[i]=dataX_high[i]-dataX_high[i-1]; //間隔を計算 dif1_high[i]=(dataY_high[i]-dataY_high[i-1])/h_high[i]; //一次微分を計算 } for(i=1;i<data_count_high - 1;i++){ //二次微分を計算 dif2_high[i]=(dif1_high[i+1]-dif1_high[i])/(dataX_high[i+1]-dataX_high[i-1]); } i=1; for(x = dataX_high[0];x < dataX_high[data_count_high - 1];x+=0.01){ if(x < dataX_high[i]){ yy0=dif2_high[i-1]/(6*h_high[i])*(dataX_high[i]-x)*(dataX_high[i]-x)*(dataX_high[i]-x); //第1項 yy1=dif2_high[i]/(6*h_high[i])*(x-dataX_high[i-1])*(x-dataX_high[i-1])*(x-dataX_high[i-1]); //第2項 yy2=(dataY_high[i-1]/h_high[i]-h_high[i]*dif2_high[i-1]/6)*(dataX_high[i]-x); //第3項 yy3=(dataY_high[i]/h_high[i]-h_high[i]*dif2_high[i]/6)*(x-dataX_high[i-1]); //第4項 y=(yy0+yy1+yy2+yy3); g.drawRect(X0+(int)(10*x),Y0+(int)(10*(y)),0,0); } else i++; } // g.drawLine(out_line_x[7],out_line_y[7],out_line_x[8],out_line_y[8]); }