POV-Ray : Newsgroups : povray.binaries.images : Is there a spline solution out there? : Re: Is there a spline solution out there? Server Time
4 Nov 2024 14:00:10 EST (-0500)
  Re: Is there a spline solution out there?  
From: Ben Birdsey
Date: 10 Aug 2000 05:13:27
Message: <39927420.84C3B588@netscape.net>
There are a whole lotta representations for splines.  It is pretty hard
to make a suggestion, since I don't know what you want your spline to
look like.

	So, let me suggest a beta-spline.  This is a cubic spline, but two of
the end matching conditions are relaxed to give you two more parameters
to tweak (skewness and tension).  This can give you all sorts of cool
effects including "sharp" corners id you turn up the tension at a node.

	If you're up to it, you could probably convert this C-code to POV, but
I'm not sure if this'll compile without errors as is.

	Good luck on finding your spline solution!

	In Him,
	Ben


/* C-code follows */


float BernsteinP3(int order, float u)  {

	float rv;

	if(order>3 || order<0) return -HUGEVAL; /* return an error */

	switch(order) {
		case 0:
			rv = (1-u)*(1-u)*(1-u);
			break;
		case 1:
			rv = 3*u*(1-u)*(1-u);
			break;
		case 2:
			rv = 3*u*u*(1-u);
			break;
		case 3:
			rv = u*u*u;
	};

	return rv;
}


float BetaP(int order, float s, float t, float u)  {

	float rv;
	float delta = 2*s*s*s + 4*s*s + 4*s + t + 2;


	if(order>1 || order<-2) return -HUGEVAL; /* return an error */

	switch(order) {
		case -2:
			rv = 12./d * s*s*s * BernsteinP3(0.,u);
			break;
		case -1:
			rv =
				2.*s*(s+1.)/d*( 
					2.*BernsteinP3(0,u) +
					(1.+s)*BernsteinP3(1,u) +
					s*BernsteinP3(2,u) +
					s*s*BernsteinP3(3,u)
				) + 
				t/d*(BernsteinP3(0,u) + BernsteinP3(1,u));
			break;
		case 0:
			rv =
				2./d*(
					BernsteinP3(0,u) +
					(1+s)*BernsteinP3(1,u) +
					(1+s)*(1+s)*BernsteinP3(2,u) +
					2*s*(1+s)*BernsteinP3(3,u)
				) + 
				t/d*(BernsteinP3(2,u) + BernsteinP3(3,u));
			break;
		case 1:
			rv = 2./d * BernsteinP3(3,u);
	};

	return rv;
}



float BetaSpline( float control_point[], int i, float s[], float t[],
float u ) {
	float rv;
	int j;

	if( u<0. || u>1.) return -HUGEVAL; /* return an error */

	/* the array must be defined to be as large as MAXVAL, or you might get
an error */
	for(j=-2, rv=0; j<2; j++)
		if(i+j>=0 && i+j <MAXVAL)
			rv += control_point[i+j] * BetaP(j, s[i], t[i], u);

	return rv;
	
}

/* end C-code */


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.