import java.io.*;
import javax.swing.*;

class SCO11B6
{
//Bernstein polinomları ve Bezier eğrisi (bir boyutlu)
  public static double[] B(int n,double t)
  { //  0<=t<=1
	double b[]=new double[n+1];
    b[0]=1.0;
    for(int i=1;i<=n;i++) 
    {b[i]=t*b[i-1];
     for(int j=i-1;j>=1;j--)
     {b[j]=(1.0-t)*b[j]+t*b[j-1];}
     b[0]=(1.0-t)*b[0];
    }
  return b;
  }
  
  public static double funcB(double a[],double t)
  { double xx=0;
    int n=a.length-1;
    double b[]=B(n,t);
    for(int i=0;i<=n;i++) 
    {xx+=a[i]*b[i];}
  return xx;
  }
  
  public static double[][] Bezier(double xi[],double yi[],int noktasayisi)
  {
	int n=xi.length;
	double z[][]=new double[2][noktasayisi];
    double dt=1.0/(double)noktasayisi;
    double t=0;
    int k=0;
    int i;
    for(i=0;i<noktasayisi;i++)
       {z[0][i]=funcB(xi,t);z[1][i]=funcB(yi,t);
        t=t+dt;
       }
    return z;
  }
  
  public static void main(String args[]) throws IOException
  {
  double x[];
  double y[];
  String s1="a.txt";
  //JFileChooser fc=new JFileChooser();
  //if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {File file = fc.getSelectedFile();s1=file.getName(); }
  double a[][]=Text.readDoubleT(s1);
  x=a[0];
  y=a[1];  
  int n=x.length;
  //for(double t=0;t<=1.0;t+=0.1) {System.out.println(funcB(4,x,t)+" "+funcB(4,y,t));}
  double z1[][]=Bezier(x,y,100);
  //System.out.println("E.K.K. z1\n"+Matrix.toString(Matrix.T(z1))); 
  Plot pp=new Plot(z1[0],z1[1]);
  pp.setPlabel("Bezier  yöntemi eğri uydurma");
  pp.setXlabel("x");
  pp.setYlabel("y");
  pp.setPlotType(0,0); 
  pp.addData(x,y);
  pp.addData(x,y);
  pp.setPlotType(2,18); 
  pp.plot();
  }
}
