POV-Ray : Newsgroups : povray.binaries.images : Is there a spline solution out there? Server Time
3 Nov 2024 03:01:43 EST (-0500)
  Is there a spline solution out there? (Message 1 to 10 of 17)  
Goto Latest 10 Messages Next 7 Messages >>>
From: Greg M  Johnson
Subject: Is there a spline solution out there?
Date: 9 Aug 2000 15:31:58
Message: <3991B07C.4A0CAE1F@my-dejanews.com>
I want a smoothly varying function that goes between the following
points:
    <0.00, -15>,
    <0.25, -125>,
    <0.45, -110>,
    <0.50, -10>,
    <0.75, -25>,
    <1.00, -15>

The function/ spline will serve as a keyframing notation for the joints
in a body, ala < timei , thetai >. Such that if I call out 0.375 for the
x, I should get something not too far from 117.

My own "cosinespline" is inadequate (see 04/14/00 posting) :  not much
better than straight lines.  Chris Colefax's macro has a ton of options
which offer some promise, but it is woefully lacking an adequate
explanation of what he dreamed up. I'm suspecting it cannot even handle
an irregular list like above.

Can anyone help me?


Post a reply to this message


Attachments:
Download 'cossplinevscubic.jpg' (27 KB)

Preview of image 'cossplinevscubic.jpg'
cossplinevscubic.jpg


 

From: H  E  Day
Subject: Re: Is there a spline solution out there?
Date: 9 Aug 2000 19:52:51
Message: <01c0025c$e8abe4c0$817889d0@daysix>
| I want a smoothly varying function that goes between the following
| points:
|     <0.00, -15>,
|     <0.25, -125>,
|     <0.45, -110>,
|     <0.50, -10>,
|     <0.75, -25>,
|     <1.00, -15>
Have you tried the spline {} Megapov function?  This is what I use for all
my keyframing.  It's not perfect, but with a bit of modification you can
make it do anything.

H.E. Day
<><


Post a reply to this message

From: Libellule
Subject: Re: Is there a spline solution out there?
Date: 10 Aug 2000 00:12:02
Message: <39922BC9.E0039D3C@insectes.net>
There is the standard cubic spline:

Provide 'n' through-points <xi, yi>, and it gives 'n-1' cubic polynomials,
one  for each range[<xi,yi>-<x(i+1),y(i+1)>], with position, first, and second
derivative continuity.

The method might not be amenable to a POV solution, though, because you solve
a system of linear equations to get the coefficients for the cubic
polynomials, which is something that might be inefficient in POV script.


Post a reply to this message

From: Ben Birdsey
Subject: Re: Is there a spline solution out there?
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

From: Libellule
Subject: Cubic spline mentioned above 18kbbu
Date: 11 Aug 2000 00:25:02
Message: <3993804F.36A34A26@insectes.net>
Using the data in the original post
(Solved externally)
Data points shown with slightly larger spheres than the rest


Post a reply to this message


Attachments:
Download 'cubicspline.jpg' (18 KB)

Preview of image 'cubicspline.jpg'
cubicspline.jpg


 

From: Greg M  Johnson
Subject: Re: Cubic spline mentioned above 18kbbu
Date: 11 Aug 2000 09:23:50
Message: <3993FD39.52D9976@my-dejanews.com>
This is actually supposed to be the rotation of a knee across a walk cycle. In
your solution, which is very similar to mine, the knee would be bending
backwards (theta>>0) during part of the cycle.  If you look at my solution in
the blue curve that I posted, it is devoid of the above error, but so flat it
is not much  better than straight lines.



Libellule wrote:

> Using the data in the original post
> (Solved externally)
> Data points shown with slightly larger spheres than the rest
>
>   ------------------------------------------------------------------------
>  [Image]


Post a reply to this message

From: Greg M  Johnson
Subject: Re: Is there a spline solution out there?
Date: 11 Aug 2000 09:24:43
Message: <3993FD6E.C2FD0D1F@my-dejanews.com>
Thanks, but I want it to work WITHIN pov. It's the angle of rotation of a knee in a
walk cycle.  This is come kind of "C" code, no?

Ben Birdsey wrote:

>         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

From: Greg M  Johnson
Subject: Re: Is there a spline solution out there?
Date: 11 Aug 2000 09:28:15
Message: <3993FE3D.6C69C2D@my-dejanews.com>
I think the green and/or red curves are typical of what one sees with the mega
splines.

I think Colefax's spline has lots of neat knobs & levers, but no explanation
in the available tuts.

"H. E. Day" wrote:

> | I want a smoothly varying function that goes between the following
> | points:
> |     <0.00, -15>,
> |     <0.25, -125>,
> |     <0.45, -110>,
> |     <0.50, -10>,
> |     <0.75, -25>,
> |     <1.00, -15>
> Have you tried the spline {} Megapov function?  This is what I use for all
> my keyframing.  It's not perfect, but with a bit of modification you can
> make it do anything.
>
> H.E. Day
> <><


Post a reply to this message

From: Libellule
Subject: Re: Cubic spline mentioned above 18kbbu
Date: 11 Aug 2000 09:57:44
Message: <39940692.38F86AEA@insectes.net>
Oh well, I tried :)


Post a reply to this message

From: Jerry Anning
Subject: Re: Is there a spline solution out there?
Date: 11 Aug 2000 10:51:14
Message: <39940f6a.4076614@news.povray.org>
On Fri, 11 Aug 2000 09:19:42 -0400, "Greg M. Johnson"
<gre### [at] my-dejanewscom> wrote:

>Thanks, but I want it to work WITHIN pov. It's the angle of rotation of a knee in a
>walk cycle.  This is come kind of "C" code, no?

Here are the key guts of a Tau spline implementation within pov.  The
Tau spline is a Catmull-Rom spline with tension and bias parameters.
This means that:
 it will pass through the control points
you can control how much it bends (and how smooth the curve is) with
tension
you can control which end of a segment the maximum bend is near with
bias.
Incidentally, the cubic interpolation (cerp) and Horner's method
(horn) macros can create many other spline types with an appropriate
control matrix.  You should be able to figure out the rest from here.
If not email and I will send you a full demo as health permits.
This expects your control points to be in the array Points and  Bias
and Tens to be (0 to 1) variables already declared.  The other
variables are either obvious or irrelevant material from the original
project.

// begin partial code snippet
#macro Mxv(In, Mx)
  <max(In.x, Mx.x), max(In.y, Mx.y), max(In.z, Mx.z)>
#end

#macro Mnv(In, Mn)
  <min(In.x, Mn.x), min(In.y, Mn.y), min(In.z, Mn.z)>
#end

#declare Tau = array[4][4]
  {
    { (Bias - 1) * Tens, 2 - Bias * Tens, (1 - Bias) * Tens - 2, Bias
* Tens },
    { 2 * (1 - Bias) * Tens, (3 * Bias - 1) * Tens - 3, 3 - Tens,
-Bias * Tens },
    { (Bias - 1) * Tens, (1 - 2 * Bias) * Tens, Bias * Tens, 0 },
    { 0, 1, 0, 0 }
  }
  
#macro Horn(Row, Pt)
  (T * ( T * (T * Tau[0][Row] + Tau[1][Row]) + Tau[2][Row]) +
Tau[3][Row]) * Pt
#end

#macro Cerp(Pf)
  Horn(0, Points[Pf - 1]) + Horn(1, Points[Pf]) +
  Horn(2, Points[Pf + 1]) + Horn(3, Points[Pf + 2])
#end

union
  {
    #declare Iter = 1;
    #while(Iter < Dim + 2 * Close)
      #declare Count = max(1, int(Fine * vlength(Points[Iter + 1] -
Points[Iter])));
      #declare Incr = 1 / Count;
      #declare T = 0;
      #while(T < 1)
        #declare Start = Mxv(Mnv(Cerp(Iter), <24 * Aspect, 24, 24>),
                         <-24 * Aspect, -24, 0>);
        #declare T = T + Incr;
        #declare End = Mxv(Mnv(Cerp(Iter), <24 * Aspect, 24, 24>),
                       <-24 * Aspect, -24, 0>);
        #declare End = ((End.x = Start.x) ? End + <.001, 0, 0> : End);
        sphere { Start, Width }
        cylinder { Start, End, Width }

      #end
    #end
  }
// end partial code snippet
Jerry Anning
clem "at" dhol "dot" org


Post a reply to this message

Goto Latest 10 Messages Next 7 Messages >>>

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