/* Test program for C code from An Introduction to NURBS by David F. Rogers. Copyright (C) 2000 David F. Rogers, All rights reserved. Name: tbspline.c Purpose: B-spline curve generator for periodic curves Chap3, Sec. 3.7 Language: C Subroutines called: bsplineu.c Book reference: Chapter 3 */ main(){ int i; int npts,k,p1; float b[34]; /* allows for up to 11 control vertices */ float p[103]; /* allows for up to 100 points on curve */ npts = 11; k = 4; /* fourth order */ p1 = 21; /* eleven points on curve */ for (i = 1; i <= 3*npts; i++){ b[i] = 0.; } for (i = 1; i <= 3*p1; i++){ p[i] = 0.; } /* Define the control polygon, Ex. 3.7 in the z=1 plane because this is three dimensional routine. x=b[1], y=b[2], z=b[3], etc. Although this is the Ex. 3.7 control polygon, matrix methods are NOT used to generated the curve. */ b[1]=0; b[2]=0; b[3]=1; b[4]=2; b[5]=0; b[6]=1; b[7]=4; b[8]=0; b[9]=1; b[10]=4; b[11]=2; b[12]=1; b[13]=4; b[14]=4; b[15]=1; b[16]=2; b[17]=4; b[18]=1; b[19]=0; b[20]=4; b[21]=1; b[22]=0; b[23]=2; b[24]=1; b[25]=0; b[26]=0; b[27]=1; b[28]=2; b[29]=0; b[30]=1; b[31]=4; b[32]=0; b[33]=1; /* Comment out the above control polygon, change npts to npts = 4 and uncomment the control polygon below to test Ex. 3.6 on p. 70. */ /* b[1]=0; b[2]=0; b[3]=1; b[4]=3; b[5]=9; b[6]=1; b[7]=6; b[8]=3; b[9]=1; b[10]=9; b[11]=6; b[12]=1; */ bsplineu(npts,k,p1,b,p); printf("\nPolygon points\n\n"); for (i = 1; i <= 3*npts; i=i+3){ printf(" %f %f %f \n",b[i],b[i+1],b[i+2]); } printf("\nCurve points\n\n"); for (i = 1; i <= 3*p1; i=i+3){ printf(" %f %f %f \n",p[i],p[i+1],p[i+2]); } }