/* Test program for C code from An Introduction to NURBS by David F. Rogers. Copyright (C) 2000 David F. Rogers, All rights reserved. Name: trbsplin.c Purpose: Test rational B-spline curve generator Chapter 4 Language: C Subroutines called: rbspline.c Book reference: Chapter 4, Ex. 4.1, Alg. p 297 */ main(){ int i; int npts,k,p1; float b[31]; /* allows for up to 10 control vertices */ float h[11]; /* allows for up to 10 control vertices */ float p[103]; /* allows for up to 100 points on curve */ npts = 5; k = 3; /* third order, change for other orders */ p1 = 11; /* eleven points on curve */ for (i = 1; i <= 3*npts; i++){ b[i] = 0.; } /* set all homogeneous weighting factros to 1.0 */ for (i=1; i <= npts; i++){ h[i] = 1.0; } /* vary the homogeneous weighting factor 0, 0.25, 1.0, 5.0 */ h[3] = 1; for (i = 1; i <= 3*p1; i++){ p[i] = 0.; } /* Define the control polygon, Ex. 4.1, p. 140 in the z=1 plane because this is three dimensional routine. x=b[1], y=b[2], z=b[3], etc. */ b[1]=0; b[2]=0; b[3]=1; b[4]=1; b[5]=2; b[6]=1; b[7]=2.5; b[8]=0; b[9]=1; b[10]=4; b[11]=2; b[12]=1; b[13]=5; b[14]=0; b[15]=1; rbspline(npts,k,p1,b,h,p); printf("\nPolygon points\n"); for (i = 1; i <= 3*npts; i=i+3){ printf(" %f %f %f \n",b[i],b[i+1],b[i+2]); } printf("\nHomogeneous weighting vector is \n"); for (i = 1; i <= npts; i++){ printf(" %f ", h[i]); } printf("\n"); printf("\nCurve points\n"); for (i = 1; i <= 3*p1; i=i+3){ printf(" %f %f %f \n",p[i],p[i+1],p[i+2]); } }