//BRYAN WEIR
//1.12 PS 6
//Problem 2, B_spline
//17 April 97

#define null 0
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#include <fstream.h>
#include "Matrix.cc"

int main()
{
Matrix Dat(3, 4);
Matrix Bspl(101, 2);
double temp, u;


ifstream crap ("pelton.in");

for(int i=0; i<2; i++)
  {
    for(int j=0; j<4; j++)
      {
	crap >> temp;
	Dat.set(i, j, temp);
      }
  }
crap.close();

for(int j=0; j<4; j++)
  {
    Dat.set(2, j, Dat.get(0, j) * Dat.get(1, j)/10000);
  }

double x0 = Dat.get(0, 0);
double x1 = Dat.get(0, 1);
double x2 = Dat.get(0, 2);
double x3 = Dat.get(0, 3);
double y0 = Dat.get(2, 0);
double y1 = Dat.get(2, 1);
double y2 = Dat.get(2, 2);
double y3 = Dat.get(2, 3);

for (int i=0; i<101; i++)
  {
    u = (double)i/100;
    temp = (1.0/6.0) * (1-u) * (1-u) * (1-u) *x0;
    temp = temp + (1.0/6.0) * (3*u*u*u - 6*u*u + 4)*x1;
    temp = temp + (1.0/6.0) * (-3*u*u*u + 3*u*u + 3*u +1)*x2;
    temp = temp + (1.0/6.0)*u*u*u*x3;

    Bspl.set(i, 0, temp);

    temp = (1.0/6.0) * (1-u) * (1-u) * (1-u) *y0;
    temp = temp + (1.0/6.0) * (3*u*u*u - 6*u*u + 4)*y1;
    temp = temp + (1.0/6.0) * (-3*u*u*u + 3*u*u + 3*u +1)*y2;
    temp = temp + (1.0/6.0)*u*u*u*y3;

    Bspl.set(i, 1, temp);
  }

ofstream output ("B_spline.out");

for (int i=0; i<101; i++)
  output << Bspl.get(i, 0) << " " << Bspl.get(i, 1) << endl;

}




