POV-Ray : Newsgroups : povray.binaries.images : Fixed cosinespline Server Time
2 Oct 2024 18:22:40 EDT (-0400)
  Fixed cosinespline (Message 1 to 8 of 8)  
From: Greg M  Johnson
Subject: Fixed cosinespline
Date: 12 Apr 2000 16:19:55
Message: <38F4D961.4F97FA95@my-dejanews.com>
Tor Olav Kristensen fixed one problem with my sinespline and then I saw
that what I really needed was a CosineSpline!
Here is a test scene, all fixed up!
Red dots:    linear poitns
Yellow curve: #init_spline
Blue curve: Cosine spline

The yellow #init_spline gives the most smooth curve, but it's not too
proud to stay within the range of original points. The blue curve isn't
the smoothest or prettiest, but it behaves.

-------------------------------------
test scene

#version 3.1;
#include "colors.inc"
//by Greg M. Johnson and improved by Tor Olav Kristensen

#macro sinespline(xgive, ptArray)

  #local jj = 0;
  #local nextx = ptArray[jj].x;
  #local Found = false;
  #while (!Found & (jj < dimension_size(ptArray, 1) - 1))
    #local lastx = nextx;
    #local jj = jj+1;
    #local nextx = ptArray[jj].x;
    #local Found = ((xgive >= lastx) & (xgive < nextx) ? true : false);
  #end // while

  (Found ? ptArray[jj].y +
           (ptArray[jj-1] - ptArray[jj]).y*
           0.5*(
                cos
                       (pi*
                        (xgive - lastx)/(nextx - lastx)
                       )+1
               )
         : 0)

#end // macro sinespline

#init_spline {"initspline",
  < 0.000,  -15.0 >,
  < 0.250, -125.0 >,
  < 0.450, -110.0 >,
  < 0.500,  -10.0 >,
  < 0.750,  -25.0 >,
  < 1.000,  -15.0 >
}


#declare pn =
array[6] {
  < 0.000,  -15.0 >,
  < 0.250, -125.0 >,
  < 0.450, -110.0 >,
  < 0.500,  -10.0 >,
  < 0.750,  -25.0 >,
  < 1.000,  -15.0 >
}



#declare Radius = 3;
#declare sc = <300, 1, -3>;
#declare Cnt = 0;
#while(Cnt < 1)
  sphere {
    <Cnt, sinespline(Cnt, pn), 1>*sc, Radius
    pigment{ Blue }
    finish{ ambient 1 }
  }
  #declare Cnt = Cnt + .002;
#end
#declare Cnt = 0;
#while(Cnt < 1)
  sphere {
    <Cnt, eval_spline ("initspline",Cnt), 4>*sc, Radius*0.5
    pigment{ Yellow }
    finish{ ambient 1 }
  }
  #declare Cnt = Cnt + .006;
#end

#declare Cnt = 0;
#while(Cnt < dimension_size(pn, 1))
  sphere {
    <pn[Cnt].x, pn[Cnt].y, 1>*sc, Radius*1.25
    pigment{ Red }
    finish{ ambient 1 }
  }
  #declare Cnt = Cnt + 1;
#end


camera {
  location  <130, -75, -300>
  look_at   <130, -75,  0.0>
}


Post a reply to this message


Attachments:
Download 'cosinespline.jpg' (16 KB)

Preview of image 'cosinespline.jpg'
cosinespline.jpg


 

From: Peter Popov
Subject: Re: Fixed cosinespline
Date: 12 Apr 2000 16:51:54
Message: <f7o9fskbmaqos7hfch3lh5sh5jch7mtkf7@4ax.com>
On Wed, 12 Apr 2000 16:15:29 -0400, "Greg M. Johnson"
<gre### [at] my-dejanewscom> wrote:

>Tor Olav Kristensen fixed one problem with my sinespline and then I saw
>that what I really needed was a CosineSpline!

Maybe you could use a cubic spline instead. Take -2*x^3+3*x^2 in the
region [0;1]. It has a minimum at [0,0], a maximum at [1,1], a point
of inflexion at [0.5,0.5] and is symmetric about [0.5,0.5] . Who could
ask for more? :)


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Fixed cosinespline
Date: 12 Apr 2000 19:05:52
Message: <38F50020.4A2F5E70@online.no>
"Greg M. Johnson" wrote:

> Tor Olav Kristensen fixed one problem with my sinespline and then I saw
> that what I really needed was a CosineSpline!
> Here is a test scene, all fixed up!

...

> #macro sinespline(xgive, ptArray)
> ...
> #end // macro sinespline

You may want to rename the macro to cosinespline then ?

;-)

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Fixed cosinespline
Date: 12 Apr 2000 19:20:26
Message: <38F50394.70DBFF49@online.no>
Peter Popov wrote:

> Maybe you could use a cubic spline instead.
> Take -2*x^3+3*x^2 in the region [0;1].

I tried your suggestion to use the cubic spline above.

I found that it doesn't differ much from Greg's cosine spline.
(I used the points that he put in his sample scene file.)

Is that the way it should be?

> It has a minimum at [0,0], a maximum at [1,1], a point
> of inflexion at [0.5,0.5] and is symmetric about [0.5,0.5]
> Who could ask for more? :)

Do you know of any other interesting polynomials for splines?

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

From: Peter Popov
Subject: Re: Fixed cosinespline
Date: 13 Apr 2000 06:38:07
Message: <9a8bfs4pjbovor4a2ltbe1a8sl5ho62u8v@4ax.com>
On Thu, 13 Apr 2000 01:15:32 +0200, Tor Olav Kristensen
<tto### [at] onlineno> wrote:

>
>Peter Popov wrote:
>> Take -2*x^3+3*x^2 in the region [0;1].

>I tried your suggestion to use the cubic spline above.

>I found that it doesn't differ much from Greg's cosine spline.
>(I used the points that he put in his sample scene file.)

>Is that the way it should be?

Well, it shares the same properties with the cosine spline (minima,
maxima, symmetry, point of inflexion) so it doesn't differ much. Both
are used in POV.

>Do you know of any other interesting polynomials for splines?

No, I don't, but I am sure the various spline macros have them.

I am interested to see if this makes any sense (untested!):

y = [-2*(x+0.5)^3+3*(x+0.5)^2-0.5]^n , where n is real

This time we're interested in the values of y for x [-0.5; 0.5]. The
spline has a minimum at [-0.5, -0.5], a maximum at [0.5, 0.5], a point
of inflexion at the origin and is an odd function. The parameter n
should control the steepness of the slope, but preserving the
smoothness of the spline and its scope.


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Greg M  Johnson
Subject: Re: Fixed cosinespline
Date: 13 Apr 2000 08:00:28
Message: <38F5B5D5.920564BE@my-dejanews.com>
My use for a spline is to make keyframes for a walk cycle. It's hard enough
to figure out how to figure out the points _within my range_ to look right.
I find it mentally aggravating to have to 'add' two extra points on either
side to figure out how to make it smooth and well-behaved. If I were making
a solitary camera path, yes I might use a cubic spline, but not when I have
8-16 splines to manage at once!

Notgonnadoitwouldn'tbeprudentatthisjuncture.

Peter Popov wrote:

> On Wed, 12 Apr 2000 16:15:29 -0400, "Greg M. Johnson"
> <gre### [at] my-dejanewscom> wrote:
>
> >Tor Olav Kristensen fixed one problem with my sinespline and then I saw
> >that what I really needed was a CosineSpline!
>
> Maybe you could use a cubic spline instead. Take -2*x^3+3*x^2 in the
> region [0;1]. It has a minimum at [0,0], a maximum at [1,1], a point
> of inflexion at [0.5,0.5] and is symmetric about [0.5,0.5] . Who could
> ask for more? :)
>
> Peter Popov ICQ : 15002700
> Personal e-mail : pet### [at] usanet
> TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Peter Popov
Subject: Re: Fixed cosinespline
Date: 13 Apr 2000 15:43:45
Message: <kn8cfsge7mblmkhci5v1l10pj7l8jv0k11@4ax.com>
On Thu, 13 Apr 2000 07:56:05 -0400, "Greg M. Johnson"
<gre### [at] my-dejanewscom> wrote:

>My use for a spline is to make keyframes for a walk cycle. It's hard enough
>to figure out how to figure out the points _within my range_ to look right.
>I find it mentally aggravating to have to 'add' two extra points on either
>side to figure out how to make it smooth and well-behaved. If I were making
>a solitary camera path, yes I might use a cubic spline, but not when I have
>8-16 splines to manage at once!

But... but... you only need to scale the spline so that the range
[0,0] to [1,1] maps onto the rectangle formed by a point and the next
one you want your spline to pass through...


Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG      e-mail : pet### [at] tagpovrayorg


Post a reply to this message

From: Greg M  Johnson
Subject: Re: Why cubic spline sucks
Date: 14 Apr 2000 10:46:58
Message: <38F72E4E.642E2640@my-dejanews.com>
Peter Popov wrote:

> But... but... you only need to scale the spline so that the range
> [0,0] to [1,1] maps onto the rectangle formed by a point and the next
> one you want your spline to pass through...

Please find enclosed a photo comparing the cubic spline, the #init_spline, and
the COSINE SPLINE.

The cubic spline is a pain because:
1) You have to make up two points before and after: in coding something like a
walk cycle, that's about another 12-16 points that have to be retyped every time
you make a little tweak.
2) It wildly varies from the range of the points.  Look at the image: if I were
keyframing a walk cycle with a cubic spline, I'd have a leg that sometimes bends
backwards +45 degrees, when I had coded in a range of [-10,-125]. It would be a
herculean effort to get this not to violate the range--and then it would be a
bear to edit as I gradually improved the walk cycle--a process that might
involve dozens of iterations. Not only do I have to type in extra numbers, but
it varies from the range in ways that makes it useless unless you are:

A) in need of a perfectly smooth, elegant camera path.
B) really making a curve that is replaceable by the cosine function itself.


Post a reply to this message


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

Preview of image 'cossplinevscubic.jpg'
cossplinevscubic.jpg


 

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