Curve interpolation algorithm

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
morevnaproject
Posts: 3
Joined: Sun May 26, 2024 12:17 am

Curve interpolation algorithm

Post by morevnaproject »

Hi everyone!
I am writing a python script to convert from Moho format to other vector software.
The script is already capable to extract points and convert simple shapes.
But I cannot figure out how Moho interpolates curve between points. Is there any documentation for this algorithm available?
Thanks in advance!
User avatar
synthsin75
Posts: 10363
Joined: Mon Jan 14, 2008 2:20 pm
Location: Oklahoma
Contact:

Re: Curve interpolation algorithm

Post by synthsin75 »

If memory serves, I believe it's cubic beziers, defined by 4 points.

Hayasidist knows all about that. Hopefully he chimes in.
User avatar
hayasidist
Posts: 3907
Joined: Wed Feb 16, 2011 11:12 am
Location: Kent, England

Re: Curve interpolation algorithm

Post by hayasidist »

yeah cubic bezier. Assuming you know what that is:

the actual Moho points are P0 and P3. You then need to derive P1 and P2 from the way Moho stores the "curvature" -- see https://mohoscripting.com/snippets/5
User avatar
SimplSam
Posts: 1241
Joined: Thu Mar 13, 2014 9:09 am
Location: London, UK
Contact:

Re: Curve interpolation algorithm

Post by SimplSam »

Also note: If you are reading the Moho JSON data - in some cases you may not get the true position of the points - if they are influenced by Bones, Actions, Smart Actions, Physics, Meshes or Curvers.
Moho 14.3 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
morevnaproject
Posts: 3
Joined: Sun May 26, 2024 12:17 am

Re: Curve interpolation algorithm

Post by morevnaproject »

Awesome! Thank you so much for responding, everyone!
The information you provided helps a lot!
morevnaproject
Posts: 3
Joined: Sun May 26, 2024 12:17 am

Re: Curve interpolation algorithm

Post by morevnaproject »

hayasidist wrote: Sun Aug 11, 2024 5:10 am yeah cubic bezier. Assuming you know what that is:

the actual Moho points are P0 and P3. You then need to derive P1 and P2 from the way Moho stores the "curvature" -- see https://mohoscripting.com/snippets/5
Hi! I have made tests and the script you referenced and found that it doesn't give correct results: coordinates of P1 and P2 are not calculated correctly.
It is easy to check just by comparing its results with output of GetControlHandle() function.

So, are there any other information available how to find coordinates of P1 and P2?
Will much appreciate any hint!
User avatar
hayasidist
Posts: 3907
Joined: Wed Feb 16, 2011 11:12 am
Location: Kent, England

Re: Curve interpolation algorithm

Post by hayasidist »

odd -- the script writer (Alexandra) who created that snippet (back in 2017) rarely gets things badly wrong and has likely used that code in her scripts. Can you please check that you're calling it and GetControlHandle consistently. Also note that GetControlHandle returns the handle absolute position after applying all smartbones (IOW, in some circumstances a difference is expected!)

If you're still convinced that it is an error in the algorithm, then can you please upload the code (and, if necessary, the moho file) that shows the error so someone can take a deeper look!
Post Reply