/* Test program for C code from An Introduction to NURBS by David F. Rogers. Copyright (C) 2000 David F. Rogers, All rights reserved. Name: trbasis.c Purpose: test the rational basis function routine Language: C Subroutines called: knot.c Book reference: Chapter 4, Ex. 4.1 , Alg. p 296 */ #include main() { int i, index; int c,npts,nplusc; int x[22]; float t; float h[20]; float r[20]; float sum; float hnew; t = 0.; printf("Input number of polygon points and order separated by a space npts c "); scanf("%d %d",&npts,&c); nplusc = npts + c; for (i=1; i <= npts; i++){ h[i] = 1.0; } printf("If any homogeneous weighting factor is not 1.0, then \n"); printf("input number index and value separated by a space, i.e., index h[index] \n"); printf("Enter 0 0 to skip "); scanf("%d %f",&index,&hnew); if (( index > 0) && (index <= npts)) h[index]=hnew; knot(npts,c,x); printf("knot vector is \n"); for (i = 1; i <= nplusc; i++){ printf(" %d ", x[i]); } printf("\n"); printf("Homogeneous weighting vector is \n"); for (i = 1; i <= npts; i++){ printf(" %f ", h[i]); } printf("\n"); while(( t >= 0.) && (t <= (float)x[nplusc])){ printf("Input the parameter value t (Control C to end) "); scanf("%f", &t); printf("The parameter value t is %f\n",t); rbasis(c,t,npts,x,h,r); printf("Rational basis functions are \n"); sum = 0; for (i = 1; i <= npts; i++){ sum = sum + r[i]; } for (i = 1; i <= npts; i++){ printf("%f ", r[i]); } printf("\n"); printf("Sum of the Rational Basis functions is %f \n",sum); } }