Path: utzoo!utgpu!jarvis.csri.toronto.edu!me!ecf!apollo
From: apollo@ecf.toronto.edu (Vince Pugliese)
Newsgroups: comp.graphics
Subject: bspline program
Message-ID: <737@mv04.ecf.toronto.edu>
Date: 29 Nov 88 17:00:07 GMT
Organization: Engineering Computing Facility, University of Toronto
Lines: 82

someone requested a bspline program a while back so here is
little piece of code , not very pretty, but it "seems" to work.
have fun with it please report any errors to me.

 here is the code:

/* program to fit a b-spline to an 
arbitrary number of points v.p.*/
#include 
#include 

#define TRUE -1
#define FALSE 0

typedef
struct
{
  float x,y,z;
}
point;

char file_name[32]; 
point control_points[100];
point spline_points[50000];
int index,run_len,temp_num;
float t,deltat;
int num_points,num;
int i,j;
FILE *handle;

main()
 { 

   
     printf("enter the name of the raw point data\n" );
     scanf("%s",file_name); 



  handle=fopen(file_name,"r"); 
      i= 0;
       while (
            fscanf(handle,"%f %f %f\n",&(control_points[i].x),&(control_points[i].y),&(control_points[i].z)) != EOF) i++;   

            deltat = 0.1;

          for(index=1;index<=(i-3);index++)                 
             for(t=0.0;t<1.0;t=t+deltat) 
             {
            spline_points[num].x=((-0.16667)*t*t*t + (0.5)*t*t + (-0.5)*t + 0.16667)*control_points[index-1].x
                              +((0.5)*t*t*t -t*t + 0.66667)*control_points[index].x
                              +((-0.5)*t*t*t + (0.5)*t*t + (0.5)*t + 0.16667)*control_points[index+1].x
                              +((0.16667)*t*t*t)*control_points[index+2].x ;
          
           spline_points[num].y=((-0.16667)*t*t*t + (0.5)*t*t - (0.5)*t + 0.16667)*control_points[index-1].y
                              +((0.5)*t*t*t -t*t + 0.66667)*control_points[index].y
                              +((-0.5)*t*t*t + (0.5)*t*t + (0.5)*t + 0.16667)*control_points[index+1].y
                              +((0.16667)*t*t*t)*control_points[index+2].y ;

           spline_points[num].z=((-0.16667)*t*t*t + (0.5)*t*t - (0.5)*t + 0.16667)*control_points[index-1].z
                              +((0.5)*t*t*t -t*t + 0.66667)*control_points[index].z
                              +((-0.5)*t*t*t + (0.5)*t*t + (0.5)*t + 0.16667)*control_points[index+1].z
                              +((0.16667)*t*t*t)*control_points[index+2].z ;

               num++;
             }
            printf("here is the spline data\n");
            printf("\n");
          for(j=0;j