POV-Ray : Newsgroups : povray.binaries.scene-files : Making functions for natural cubic splines : Re: Making functions for natural cubic splines Server Time
19 Apr 2024 00:06:48 EDT (-0400)
  Re: Making functions for natural cubic splines  
From: Tor Olav Kristensen
Date: 11 Oct 2014 13:35:00
Message: <web.543969915b2bbe7b97906c220@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Something caught my eye right away as I looked through some of this.
>
>   function(t_) {
>     select(t_ - tt[0], 1, 0, 0)*ff[0](t_) +
>     #local I = 0;
>     #while (I <= N - 1)
>       select(t_ - tt[I], 0, select(t_ - tt[I+1], 1, 0))*ff[I](t_) +
>       #local I = I + 1;
>     #end // while
>     select(t_ - tt[N], 0, 1, 1)*ff[N-1](t_)
>   }
>
> It appear(ed)(s) that those "+" operators are just hanging off the edges ...
>
> Does it work by having the first result of SELECT added to the contents of the
> loop, which itself is a concatenation of SELECT results?
.....

Yes, that's right.

The select-statement in the middle just chooses one cubic polynomial function
for each of the intervals. And the select statements at the beginning and at the
end choose functions to use if t_ goes "off the ends", i.e. outside the interval
from tt[0] to tt[N].

I have made a rendering that illustrates how each set of X, Y and Z functions
contribute to each of the parts of the spline inbetween the points at tt[0],
tt[1], ... tt[N-1], tt[N]. I'll post this rendering later today or tomorrow.


> That's pretty crazy and I might need an adult beverage to even begin how it is
> that you came up with that.

Remember that this script is parsed and that the directives does not end up in
the resulting code for the scene. So the operators and the other non-directive
stuff is not "hanging loose", they are left there so that they become part of
the function that is built by the script.


Note that this is a quite powerful feature in POV-Ray; that you can build user
functions with macros.

> Not that I didn't let out a few whistles looking over some of those other
> methods.
>
> Constants reminders of
> (a) why I should have stuck with and went into writing computer software
> and
> (b) I should have definitely taken more math.
> :D

It's never too late learn new math =)

For me it was very useful to study, again, the math that I had already learned
years ago. (I did not understand how useful it could be when I learned it at
school.)

Maybe I can help with implementing these splines in BASIC, if you like.

--
Tor Olav
http://subcube.com


Post a reply to this message

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