





 
 




 
 


http://mathworld.wolfram.com/CubicSpline.html
This might help shed some light on the method, in case anyone cares to elaborate
on CatmullRom splines. (AND I'm really not all that great [read: suck] at
doing matrix math)
http://news.povray.org/povray.general/message/%3C34EA8144.4D7A8113%40dhol.com%3E/#%3C34EA8144.4D7A8113%40dhol.com%3E
http://en.wikiversity.org/wiki/Cubic_Spline_Interpolation
and a spreadsheet found by searching
cubic spline excel spreadsheet
https://newtonexcelbach.wordpress.com/2012/10/08/dailydownload22splinesandcurves/
I've not quite finished with Coffee #1, so it will take some time to wrap my
grey(ing) matter around all the pretty symbols... :)
Post a reply to this message


 
 




 
 


"Bald Eagle" <cre### [at] netscapenet> wrote:
> > It would be great to have the cubic curves displayed as such instead of
> > as line segments.
> > I don't think that is possible in JustBasic. At the very least, it would require
> > a complete rewrite of the program and the introduction of equations I can't even
> > begin to imagine.
>
> I think that it's absolutely possible, it's just a matter of knowing exactly
> what the specific equations are that POVRay uses to interpolate, so that the
> curve displayed in JustBasic will be the same as that rendered.
....
See this thread for some relevant POVRay SDL code:
Newsgroup: povray.binaries.scenefiles
Subject: Making functions for natural cubic splines
From: Tor Olav Kristensen
Date: 6th Oct 2014
http://news.povray.org/povray.binaries.scenefiles/thread/%3Cweb.54331726f5851fad7b9c043a0%40news.povray.org%3E/
I don't know JustBasic, but it might be possible to make something similar with
it.

Tor Olav
http://subcube.com
Post a reply to this message


 
 




 
 


I'm going to post this code WIP just to get it out there.
It doesn't really work  but the structure of the code is "linearized".
(To the extent that I could puzzle things out)
(You don't wanna see the flowchart I made in VISIO...)
Gotos and gosubs are like lotus flowers. I saw those and instantly fell into
some "But how would I do it _without_ that...?!" dreamscape.
Luckily I've done enough C++ coding on an Arduino with functions and subroutines
calls to see what I might do to escape that siren call.
Check out what I did with the SNAP function.  Major changes.
Also, I have filepresence checking for things like the Model.bmp
I have too many balls in the air at the moment, including some pending nasty
stuff IRL.
Adding a new point to an existing spline ought to work something like selecting
an existing point, and then clicking where the new point should appear in the
spline list AFTER that. Then you just store that point, and run a loop through
the list. If all the points have a number, then it just becomes a standard
sorting routine.
Post a reply to this message
Attachments:
Download 'splinedraw.bas.txt' (37 KB)


 
 




 
 


"Bald Eagle" <cre### [at] netscapenet> wrote:
> I'm going to post this code WIP just to get it out there.
> It doesn't really work  but the structure of the code is "linearized".
> (To the extent that I could puzzle things out)
> (You don't wanna see the flowchart I made in VISIO...)
> Gotos and gosubs are like lotus flowers. I saw those and instantly fell into
> some "But how would I do it _without_ that...?!" dreamscape.
> Luckily I've done enough C++ coding on an Arduino with functions and subroutines
> calls to see what I might do to escape that siren call.
>
> Check out what I did with the SNAP function.  Major changes.
> Also, I have filepresence checking for things like the Model.bmp
>
> I have too many balls in the air at the moment, including some pending nasty
> stuff IRL.
>
> Adding a new point to an existing spline ought to work something like selecting
> an existing point, and then clicking where the new point should appear in the
> spline list AFTER that. Then you just store that point, and run a loop through
> the list. If all the points have a number, then it just becomes a standard
> sorting routine.
Thanks for all your hard work optimizing my code. I'm not ready to upload
anything new yet, but you at least deserve an answer.
The Snap optimization looks smart. A check for file presence was implemented in
my version 1.3. And I have had some thoughts about an Insert function along the
same lines as yours. I'll take a closer look at your suggestions.
Right now I'm working on a display of cubic curves, and I agree with you that
it should be possible in JustBasic. It requires the solving of a thirddegree
polynomial for every line segment. The biggest hurdle seems to be sharp changes
in curve direction. When (and if!) I find a solution, I'll get back.
Post a reply to this message


 
 




 
 


Version 1.5, enabling you to draw with cubic curves:
* "Draw cubic" will switch from connecting your points with straight lines
(default) to connecting them with curves described by thirddegree polynomials.
This will give you a better idea of what your cubic prism or lathe will look
like when rendered in POVRay.
Cubic curves need two extra points for definition, so the drawing of connecting
curves will always be two steps behind your points. For example, when you draw
point number 4 in Cubic mode, PointWriter will connect points 2 and 3, and when
you draw point number 5, it will connect 3 and 4 and so on.
NB: Drawing in Cubic mode is very computationally demanding and can slow
your computer down, so you might work faster by drawing in Linear mode and just
switching to Cubic for quick previews.
Whether you choose to display lines or curves on the screen makes no difference
to the output when you write the shapes to POVRay code.
Keyboard shortcut: "d" (lower case). Toggle between cubic and linear.
"D" (upper case) will display your Work in Back shape with cubic curves. Toggle
between cubic and linear.
* "PointWriterHelp.txt" is updated with these changes.
Post a reply to this message
Attachments:
Download 'pointwriter.zip' (1213 KB)


 
 




 
 


Very, VERY nice!
I'm glad this feature got added  as you can see it's extremely close to
POVRay's interpolation of the spline in a sphere_sweep.
I'll try to use this new version with some of things I'm trying to model, and
let you know how everything works out.
Again  super job!
Thanks again to clipka and esp. T.O.K for so much help!
Post a reply to this message
Attachments:
Download 'cubicspline.png' (17 KB)
Preview of image 'cubicspline.png'


 
 




 
 


Good to hear!
Since clipka told me about the "t" parameter of splines in an earlier post, I
spent more hours googling parametric functions and understanding matrix solving
than writing the code :) But it seems to work now.
It'll be interesting to see what you (and others) make of this.
Post a reply to this message


 
 




 
 


"Nevado" <MYPUBLICNAME(a)sol.dk> wrote:
>.... I
> spent more hours googling parametric functions and understanding matrix solving
> than writing the code
I know exactly what you mean. I had looked over splines and matrices a number
of times in the past, but never made enough headway in understanding how to
translate the theory into anything usable.
It would be great if you could at some point share some of what you learned  I
believe several people here on the boards have expressed some interest at one
point or another in how splines are interpolated.
Post a reply to this message


 
 




 
 


"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Nevado" <MYPUBLICNAME(a)sol.dk> wrote:
>
> >.... I
> > spent more hours googling parametric functions and understanding matrix solving
> > than writing the code
>
> I know exactly what you mean. I had looked over splines and matrices a number
> of times in the past, but never made enough headway in understanding how to
> translate the theory into anything usable.
>
> It would be great if you could at some point share some of what you learned  I
> believe several people here on the boards have expressed some interest at one
> point or another in how splines are interpolated.
I'm working with some 3D splines, and I often find myself defining front, top,
and side views in my development SDL.
Perhaps a future feature would allow the editing of the zcoordinate in an
alternate view. Have a hotkey that switches view/scaling and which axis
coordinates are fixed and editable.
Post a reply to this message


 
 




 
 


"Bald Eagle" wrote:
> "Nevado" wrote:
>
> >.... I spent more hours googling parametric functions and understanding
> > matrix solving than writing the code
>
> I know exactly what you mean. I had looked over splines and matrices a number
> of times in the past, but never made enough headway in understanding how to
> translate the theory into anything usable.
>
> It would be great if you could at some point share some of what you learned 
> I believe several people here on the boards have expressed some interest at
> one point or another in how splines are interpolated.
Well, I started out just knowing that for cubic splines, some kind of
thirddegree function had to be involved.
At first I thought the function would look like I was taught in high scool math:
y = f(x) = ax^3 + bx^2 + cx + d
But clipka set me straight on that: POVRay splines are actually described by
two functions of a third parameter t,
x = f1(t) = a1t^3 + b1t^2 + c1t + d1
y = f2(t) = a2t^3 + b2t^2 + c2t + d2
thus the name parametric function. This was news to me, so I had to read up on
that and found these links useful:
https://www.cs.unm.edu/~angel/CS534/LECTURES/CS534_06.pdf
http://web.eecs.umich.edu/~sugih/courses/eecs487/lectures/37Bsplines.pdf
Knowing four x and yvalues on the spline, I could find this function by using
matrices. I read up on that here:
http://www.mathsisfun.com/algebra/matrixmultiplying.html
I learned that solving a cubic polynomial from four known points requires a 4x4
matrix involving a huge number of calculations done in a specific order.
Luckily, I could copy some of those calculations from here:
http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
And once I had them translated into JustBasic, I could test if they worked
correctly here:
http://www.mathportal.org/calculators/matricescalculators/matrixcalculator.php
So, yeah, in this kind of project, Google definitely is your friend ;)
I'm making this sound easier than it was, because some long nights were
involved, but it was also a fun challenge. I'm sure everyone in here knows the
feeling from writing a POVRay scene and clicking "Run"  and the thrill when it
works exactly like you wanted. Or when you figure out exactly why it doesn't  I
had a lot of those too.
By the way, I probably wouldn't have bothered to develop my PointWriter app this
far without your encouragement, so you deserve credit for that.
Post a reply to this message


 
 




 