/*
	Test program for C code from An Introduction to NURBS
	by David F. Rogers. Copyright (C) 2000 David F. Rogers,
	All rights reserved.
	
	Name: tdbasis.c
	Purpose: test dbasis.c uniform periodic B-spline basis functions
	         and their derivatives
	Language: C
	Subroutines called: dbasisu.c, knotu.c
	Book reference: p. 286
*/

#include 	<stdio.h>

main()
{
	int i;
	int c,npts,nplusc;
	int x[22];
	float t;
	float n[20],d1[20],d2[20];
	float sum;

	printf("Input number of polygon points and order separated by a space npts c ");
	scanf("%d %d",&npts,&c);

	t = 0.;

	nplusc = npts + c;

	knotu(npts,c,x);
		printf("knot vector is ");
		for (i = 1; i <= nplusc; i++){
			printf(" %d ",x[i]);
		}

	printf("\n\n");

	while(( t >= 0.) && (t <= (float)x[nplusc])){
		printf("Input a parameter value t (Control C to end) ");
		scanf("%f", &t);
		printf("t = ");
		printf("%f\n",t);
		dbasisu(c,t,npts,x,n,d1,d2);
		sum = 0;
		for (i = 1; i <= npts; i++){
			sum = sum + n[i];
		}
		printf("Basis functions are \n");
		for (i = 1; i <= npts; i++){
			printf("%f ", n[i]);
		}
		printf("\n");
		printf("Sum of the Basis functions is %f \n",sum);
		printf("First derivatives of the basis functions are \n");
		for (i = 1; i <= npts; i++){
			printf("%f ", d1[i]);
		}
		printf("\n");
		printf("Second derivatives of the basis functions are \n");
		for (i = 1; i <= npts; i++){
			printf("%f ", d2[i]);
		}
		printf("\n\n");
	}
}

