smooth "bezier-like" fonction from 7 sliders ?

Apr 3, 2010 at 3:48pm

smooth "bezier-like" fonction from 7 sliders ?

Hi,
I'm trying to make a smooth “bezier-like” fonction from a little multislider that would have, for example, 7 sliders. I have built a little algorythm to do this, using a kind of “slopes-means” method – see picture below – but i'm not satisfied by the result, it is not smooth enough for me.
How could i do to get a smoother result ?
Do you know any object that already do this ?

Thanks,

[attachment=128864,324]

Attachments:
  1. Image_11.png
#49509
Apr 3, 2010 at 3:56pm

hey, that looks pretty good to me. a smoothing-styled function would be a nice addition to [function] or as a new object.

You can also use filtergraph~ (with cascade~ to have multiple ones at once), then with the right filter type and other settings, your mousing will get you similar curves. just take the output and use it as you want (there’s a query inlet to get the value of any point on the curve).

#177825
Apr 3, 2010 at 4:34pm

>>hey, that looks pretty good to me.

No!!! That’s not good at all ! look at the handmade drawing below, made from the same exactly sliders values.
This is what i’m looking for.
It is quite different.
The one above really have too much “mountains” compared to this one below…

(p.s: but if you like it, the patch is in attachment)

mmh, thanks for the filtergraph idea but I don’t find this solution really practical. (i need the first value to be exactly 0., and the last exactly 1.)

Aren’t there anywhere a real “bezier” object or something similar ?

[attachment=128870,325]

Attachments:
  1. smooth_fonc.zip
#177826
Apr 3, 2010 at 5:20pm

hehe, I like the sketch. Just scan it and use that one! lol

Will take a look at your mxj, sounds interesting. Would like to see how you did the math part.

For bezier-style, maybe something with jit.gl.sketch / strokepoint / jit.gl.nurbs? Wonder if the nurbs object will do the smoothing automatically, seems like it might.

I know this topic has been talked about before, and I think there were some other examples from people on here. Not sure what the results were though.

Again, a real bezier-type object in the standard distribution would be great… or a solid way to make them out of [function] etc. via just the right math.

#177827
Apr 3, 2010 at 10:20pm

In fact i realized that my math part (very simple averaging between slopes using a cosine fonction) is just wrong for this application.

>>I know this topic has been talked about before, and I think there were some other
>>examples from people on here. Not sure what the results were though.

me too i remember more or less about a topic like this that i cannot recover. what i remember is that the result wasn’t so interesting.

>>Again, a real bezier-type object in the standard distribution would be great…

;-) ++1

>>For bezier-style, maybe something with jit.gl.sketch / strokepoint / jit.gl.nurbs?
>>Wonder if the nurbs object will do the smoothing automatically, seems like it might.

mmh… you’re the jitter pro. i found this : http://gritche.perso.libertysurf.fr/OpenGL/Bezier.html
all this gl stuff is really mysterious to me… you think you could manage some simple example using this ?

#177828
Apr 4, 2010 at 12:43am

The a-hspline3d external by André Sier. implements a Hermite spline – guaranteed to pass through the control points and allows adjustment of tension etc. I thought there was a 2d version too but I can’t find it..

#177829
Apr 4, 2010 at 3:23pm

iirc, there is a bspline object in jasch’s lib, too, so you might like to have a look there.

i did some testing of different interpolation methods some time ago.
below is a short example that compares hermite vs. windowed sinc interpolation.
i hope i got the maths right (the hermite code is from musicdsp.org i think), it looks ok though.

sinc-interpolation should be ‘smoothest’ in theory. to make it work in praxis you need to truncate the infinite function using a window. the size of it and the window function itself have a big influence on the results of the interpolation. for simplicity in the example below i used a von hann window, but if you want to get serious with this method, you should consider something more versatile, e.g. a kaiser window.
volker.

– Pasted Max Patch, click to expand. –
#177830
Apr 6, 2010 at 6:22pm

Thanks guys!

a-hspline3d is a very nice object.

Volker, I put your hermite (in your example it was looking better than sinc) algorithm in mxj (mxj is much more manageable to put severals “smooth-func” in a patch), mmh there is still some situations where i feel it be could better*, (see preset n°5), but in general it’s not that bad.

I also managed to adjust better my slope-algorithm but hermite is really better.
+ some weird curves options.

patch below.

* i don’t know if there is a way to change the “smoothness” of your hermite algorithm by changing the numerical factors ?

Attachments:
  1. smooth-func2.zip
#177831
Jul 22, 2010 at 4:35am

The thread is 3 months old, but I thought I would comment…

I wrote an external called sa.function a while back that is like the function object and has multiple lines and bezier curve support. I attached a sample file with the curve you’re looking for. It has a lot of features and requires combinations of shift/alit/cmd/ctrl/right-click to manipulate the curves, so make sure to check out the help file.

The attachment only includes a OS X external, so let me know if you’re using Windows. It’s also only for Max5.

Attachments:
  1. function_curve.zip
#177832
Jul 22, 2010 at 7:44pm

Toshiro,

Great work!!!

-Ben

#177833
Jul 22, 2010 at 10:55pm

Thanks Ben!

I also forgot to mention this:

Getting the y value of the curve requires solving an equation and sa.function has a couple of attributes to balance accuracy vs. cpu cost. @iter sets the maximum iteration the root finding algorithm will perform until it finds the root within the specified accuracy. @eps sets the accuracy and is specified as 1.0 * 10^@eps. So @eps = -6 (default) has accuracy of +/-0.000001. This means that the lower the value of @eps, the more iterations are required. If @eps is set too low, it may hit the maximum iteration set at @iter and may not produce the desired accuracy.

#177834
Sep 1, 2010 at 9:06pm

Hello Toshiro,

first of all, your sa.function is really great.

I would like to use it for my patches but it can’t be saved and recalled via pattrstorage nor preset, I’m looking for a workaround.

The second minor problem, for me in a selfish perspective :-( , is it gives only the interpolated value of the working line in multipleline mode. I would like to have sometimes 1, 2, 3 or all working in parallel, I’m looking for a workaround too.

If you’ve still time to spend on it, we never know ;-)

Thanks Toshiro

-Filippo

#177835
Oct 7, 2010 at 12:31pm

I can’t believe I only just stumbled upon this thread. Toshiro, this is brilliant. Thankyou so much, I’ve been wishing Max had something like this in the distro since I bought it, and yours is so much better and more flexible than I could have wished for!

How easy would it be to compile a Windows version too? :)

Chris

#177836
Feb 8, 2011 at 11:53pm

I just bump this thread hoping the great Toshiro will read it.

I was waiting for that object for ages so thank you very much !!!

The only problem I have is the same as Filippo : it would be cool to be able to use it with pattrstorage or preset.

For now I do it with coll…

I think it should be add to the toolbox too.

Pietro

#177837
Jul 14, 2011 at 7:35am

Once again, this thread is being bumped because of the awesomeness of sa.function!

Now, my wish for christmas this year is the merging of sa.function and ej.function…

(Emmanuel Jourdan, are you reading this?)

#177838
Aug 23, 2011 at 11:13pm

Hello again and I’m so sorry for the longest silence! I wasn’t expecting responses and I’m also not very active on the Max forum…

I very much appreciate all your feedbacks and I am happy to announce that I have a few exciting updates on sa.function!

- preset now works. I’m still working on a bug with pattrstorage… I’m hoping to have that ready sometime in the near future ;-)
- You can read multiple lines by setting the “readmultiline” attribute.
- You can “refer” to another sa.funciton and save the hassle of duplicating functions.
- You can undo/redo (!!) most editing. You can set the undo level by sending @undos when creating a sa.function. Default is 10 levels.
- And of course, this all works on Windows now.

Attachments:
  1. sa.function.zip
#177839
Aug 24, 2011 at 10:40am

man toshiro. complete awesomeness.

are you sure cycling74 haven’t contacted you yet about including this in max6 ?!?!?!

anyway, many thanks, i realise what a huge amount of skill and work that is and sharing is fantastic.

#177840
Aug 25, 2011 at 3:40am

Thanks pid! I’m glad you like it! Cycling ’74 hasn’t contacted me yet, but maybe they will soon ;-)

#177841
Sep 8, 2011 at 2:20pm

Toshiro, you’re an absolute badman. I was just muttering about this in another thread. No disrespect to the other java-based bezier function object kicking around (I forget its name…), but yours is way more responsive and slick!

And don’t forget to let us know when you iron out that pattrstorage problem! Still, now that it’s preset-compatible I don’t need my ugly hacks to dump it to and from a jitter matrix.

This really needs to be in the standard distro. It kicks arse. Maximum respec’

#177842
Sep 8, 2011 at 9:24pm

I’ve spotted a small bug (gasp!)

If you alt-click to delete a control point, no bang is sent out the right outlet.

#177843
Jan 19, 2012 at 1:39pm

I cant get [preset] working at all from the download in this post or the download at http://cycling74.com/toolbox/sa-function/

Max 5.1.9 running as M4L on max lion 10.7.2

Really really love the object a lot though ! However the issues with [pattrstorage] and [preset] are really killing it for me at the moment :(

Edit: My bad – got this working with preset, thought id closed max and changed the object but it was still open in the background when changing the object :p Im using the latest version of the patch available from the link i posted in this post. Look forward to seeing pattr working :)

#177844

You must be logged in to reply to this topic.