/* Test program for C code from An Introduction to NURBS by David F. Rogers. Copyright (C) 2000 David F. Rogers, All rights reserved. Name: tdbsplu.c Purpose: Periodic B-spline curve and derivative generator Language: C Subroutines called: dbsplinu.c Book reference: Chapter 3, Sec. 3.12, Ex. 3.8, Alg. p. 290 */ #include main(){ int i; int npts,k,p1; int ch; float b[31]; /* allows for up to 10 control vertices */ float p[103]; /* allows for up to 100 points on curve */ float d1[103]; /* allows for up to 100 points on curve */ float d2[103]; /* allows for up to 100 points on curve */ npts = 4; k = 2; /* second order, change to 4 to get fourth order */ p1 = 11; /* 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.4 in the z=1 plane because this is three dimensional routine. x=b[1], y=b[2], z=b[3], etc. */ b[1]=1; b[2]=1; b[3]=1; b[4]=2; b[5]=3; b[6]=1; b[7]=4; b[8]=3; b[9]=1; b[10]=3; b[11]=1; b[12]=1; dbspline(npts,k,p1,b,p,d1,d2); 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]); } ch = getchar(); 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]); } ch = getchar(); printf("\nCurve first derivatives\n\n"); for (i = 1; i <= 3*p1; i=i+3){ printf(" %f %f %f \n",d1[i],d1[i+1],d1[i+2]); } ch = getchar(); printf("\nCurve second derivatives\n\n"); for (i = 1; i <= 3*p1; i=i+3){ printf(" %f %f %f \n",d2[i],d2[i+1],d2[i+2]); } }