A simple Spline

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
micmac
Posts: 49
Joined: Mon May 30, 2011 9:00 am

A simple Spline

Post by micmac » Fri Jan 20, 2023 2:21 pm

A Natural Spline in its simplest form.
For you to elaborate on.

All math and coding credited to the late Herman [-hh].

Code taken from here:
http://forums.livecode.com/viewtopic.ph ... 87#p163787

Cleaned up and simplified by me.

Mic
Skærmbillede 2023-01-20 kl. 14.14.50.jpg
Attachments
Simple Spline.zip
(3.92 KiB) Downloaded 171 times
Last edited by micmac on Fri Jan 20, 2023 4:28 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: A simple Spline

Post by richmond62 » Fri Jan 20, 2023 2:31 pm

Could you please ex-spline what you want us to do with this?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: A simple Spline

Post by dunbarx » Fri Jan 20, 2023 3:41 pm

micmac

I don't see how to manipulate the red "handles". These are typically the control points in adjusting the shape of a spline curve. Nothing seems to do anything.

Craig

micmac
Posts: 49
Joined: Mon May 30, 2011 9:00 am

Re: A simple Spline

Post by micmac » Fri Jan 20, 2023 3:44 pm

richmond62 wrote:
Fri Jan 20, 2023 2:31 pm
Could you please ex-spline what you want us to do with this?
Its up to your imagination.

Mic

micmac
Posts: 49
Joined: Mon May 30, 2011 9:00 am

Re: A simple Spline

Post by micmac » Fri Jan 20, 2023 4:15 pm

dunbarx wrote:
Fri Jan 20, 2023 3:41 pm
micmac

I don't see how to manipulate the red "handles". These are typically the control points in adjusting the shape of a spline curve. Nothing seems to do anything.

Craig
OK I see it

Its probably the Behaviors that do not carry over.

I changed the stack name just before I uploaded

I reUp

micmac
Posts: 49
Joined: Mon May 30, 2011 9:00 am

Re: A simple Spline

Post by micmac » Fri Jan 20, 2023 4:23 pm

RE-UP
Corrected behaviors

Simple Spline.zip
(3.92 KiB) Downloaded 191 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: A simple Spline

Post by dunbarx » Fri Jan 20, 2023 6:29 pm

micMac.

That was probably it. Works fine now.

I miss Hermann.

Craig

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: A simple Spline

Post by stam » Sun Jan 22, 2023 12:22 am

That's really nice Mic, I'll have to spend some time digesting this as definitely have a use for something like this.

I did however very quickly run into a reproducible crash - if manipulating the red buttons I accidentally make the curve exceed the bounds of the card like this:
spline.jpg

then for me it causes an immediate crash to the debugger:
spline error.jpg
Otherwise very nice, thank you....
S.

micmac
Posts: 49
Joined: Mon May 30, 2011 9:00 am

Re: A simple Spline

Post by micmac » Sun Jan 22, 2023 10:19 am

I know Stam

As I said it was in the simplest form for you to elaborate on...

Mic

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: A simple Spline

Post by stam » Sun Jan 22, 2023 3:27 pm

micmac wrote:
Sun Jan 22, 2023 10:19 am
As I said it was in the simplest form for you to elaborate on...
Really this should be an IDE tool.
The code in the attached stack above is convoluted enough with its 1 or 2-letter variables and almost complete lack of comments/documentation that realistically I personally will probably not able to 'elaborate' on it further.

Maybe someone with actual time on their hands else can fix the code's issues (eg the crash described above, being able to change acuity of the spline angle without changing length the spline etc). I wouldn't mind the challenge of doing this myself but given my commitments that's sadly completely unrealistic.

Or maybe LC will finally improve their line-drawing tools in the new IDE and offer a spline, who knows...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: A simple Spline

Post by bn » Mon Jan 23, 2023 11:05 pm

Hermann's code threw errors when a divide by zero occurred.
For me it does not throw any errors anymore when adding the line marked by " -- Added BN" to handler computeNaturalCoefficients of the script of button "naturalSpline"

Code: Select all

on computeNaturalCoefficients
   put cpN into n
   put empty into h; put empty into l; put empty into m; put empty into z; put empty into b
   repeat with i=0 to n-1
      put xs[i+1]-xs[i] into h[i]
      if h[i] is 0 then put 1 into h[i] -- Added BN
   end repeat
   -- more code
   
This is just empirical... Not that I understand the code. (And yes Stam, I never liked these short hand variable names but then Hermann was a Mathematician and for him one letter variable names probably seemed natural)
And thanks Michael for digging this up.

Kind regards
Bernd

micmac
Posts: 49
Joined: Mon May 30, 2011 9:00 am

Re: A simple Spline

Post by micmac » Tue Jan 24, 2023 2:48 pm

Always nice when you tune in Bernd!

Added you code
Attachments
Simple Spline.zip
(3.98 KiB) Downloaded 158 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: A simple Spline

Post by bn » Wed Jan 25, 2023 12:33 pm

Thanks Michael,

Here is a link to a stack that implements bezier curves by Scott Rossi.

http://tactilemedia.com/blog/2015/12/06 ... line-demo/

It is somewhat related to this topic.

Kind regards
Bernd

Post Reply