package Maths;

import java.util.*  ;


public class Interpolating_Polynom extends Polynom{

/** this class holds the polynoms that interpolate in the given points **/


  public Interpolating_Polynom (Vector controlpoints, int degree){
	/* constructor */

	super(controlpoints, degree);

  }

  public Interpolating_Polynom (){

	/* constructor */
	super();

	this.minimal_degree = 2;
  }



 public Polynom Clone (){

	return  new Interpolating_Polynom();

 }


  protected double Alpha(int i, int j ,double val , double knotsset[]){

   /*defines the alpha used in the deBoor scheme */

    double alph;

    try {

	    alph=(val-knotsset[i-j])/(knotsset[i]-knotsset[i-j]);

	    return alph;

    }

    catch (ArithmeticException e){

            return 0;

    }

  };

 public double[] InsertNode(double val, int position){
  /* inserts a new knot and controlpoint into a curve */

  /* input :the value, the index of the controlpoint that will preceed the new controlpoint

     output :the array  the new controlpoint

	Last change:  TMC  20 Jan 98   11:04 am
   */

//System.out.println(val);
  double newcntrlp[] = Evaluate(val);// calculate the position of the new controlpoint

  int max = controlp[0].length+1;

  double newknots[][] = new double[2][knots[0].length+1];

  double newcontrolp[][] = new  double[dimension][max];


  for(int dim = 0; dim < dimension; dim++){ //inserting the new controlpoint

     System.arraycopy(controlp[dim],0,newcontrolp[dim],0,position+1); //previous points are the same

     newcontrolp[dim][position+1]= newcntrlp[dim];

     System.arraycopy(controlp[dim],position+1,newcontrolp[dim],position+2,(max-2-position));//the following points also



   }


   //inserting the new controlpoint
   System.arraycopy(knots[0],0,newknots[0],0,position+1);

   newknots[0][position+1]=val;

   newknots[1][position+1]=1;

   System.arraycopy(knots[0],position+1,newknots[0],position+2,(knots[0].length-position-1));


 controlp = newcontrolp;

//pm(controlp);


 knots = newknots;

//pm(knots);

 return newcntrlp;

 } ;

}




