-1

I know how to do linear interpolation, this is what I've build for it at the moment: http://repl.it/BBL9

What I don't see is how I'll do smooth interpolation. I'm coding a mesh deformer and I have a problem due to the in-point and end-point transitions being abrupt, the effect is cut off dramatically like the line on top in the image. I want it to be smooth like the line in the bottom:

http://i.imgur.com/XCb928D.png

So I would like to pass a float from 0.0 to 1.0 and get back the corresponding smooth interpolation float value.

If I can't code it I'm considering doing what I did in nodal editor: Have 2 arrays of 1000 sample values. The first array are values linearly interpolated values from 0.0 to 0.1, while the second is smoothed interpolated values from 0.0 to 1.0.

So I would find the closest value in the linear array and with corresponding index assign the value from the second array. I believe this is called a LUT... This would mean I could generate any curve interpolation without knowing how to calculate it, while would probably not be very accurate.

Is this last idea a bad practice if I can't code the calculation?

probiner
  • 91
  • 9
  • 2
    To avoid link rot for future readers, code must be inserted into stack overflow questions, not linked. Therefore, you may want to add the linked code directly to the question by using the "edit" link. Also, it is difficult to see what you are asking. Asking if something is a "bad practice" is likely to be considered an opinion-based question, which is off-topic here. Stack Overflow prefers focused. specific programming questions that have well-defined answers. – Paul Aug 11 '15 at 05:55
  • You need to decide on a form for your curve – David Heffernan Aug 11 '15 at 06:00
  • I edited the question. The request is quite simple given the image. I know how to do linear interpolation but feel the need of an interpolation that smooths out near 0.0 and 1.0. like again, in the image. I was considering doing a LUT if I could not come up with some calculation and wondering about the pros and cons of such alternative. – probiner Aug 11 '15 at 06:01
  • @DavidHeffernan Does the second post in this question with the image of the curve identifies the curve from I want? Thanks – probiner Aug 11 '15 at 07:38
  • No it does not. You need to supply an set of constraints that the curve needs to meet. – David Heffernan Aug 11 '15 at 07:39
  • @DavidHeffernan I do not see such constrains. What I'm after is a way to draw a smooth curve. Such constrains come from coding the curve, which I don't know how to do... – probiner Aug 11 '15 at 21:42
  • So, any smooth curve works? – David Heffernan Aug 11 '15 at 21:49
  • @DavidHeffernan What problems are there usually with this? Have you encountered problem with some smooth curves and not with others? As for me, I'm just trying to smooth out the in and out points so it doesn't look so abrupt, that's my sole goal. Maybe some curves look better than other understandably, I just not seeing the constraints you have probably dealt with before. To me if I can have code that smooths out those values and at most it gives me a parameter to test different smoothnesses fine. The code I post in the second answer already gives me some options, but I'm all ears. – probiner Aug 11 '15 at 21:57
  • A straight line is a smooth curve. Will that do? No. You appear to want at least continuity of first derivative. But you also seem to want zero second derivative. Is that right? – David Heffernan Aug 11 '15 at 22:09
  • @DavidHeffernan Yes I want continuity. But please. I'm an Arts major that have been coding a long time with nodes, meaning. I'm much more geared to visual references, so when you mention derivatives I get lost. I remember that from school: distance, velocity, acceleration, but I'm not following your point here on how to build a curve. It's because the function is a polynomial? I had math in school more than 10 years ago... If you can share visual references of the concepts you speak of I appreciate it... Sorry... – probiner Aug 11 '15 at 22:37
  • @DavidHeffernan by the way Sine, following the same type of code of the second answer seems to be ok, maybe not great in the end points: [link](http://prntscr.com/83k7kh) So maybe I do want a bezier... which is what the 3D software in the image is using of the first answer is using. So... shall I call it bezier interpolation? So I need 4 points and if I change p2 and p3 I control the smoothness? Thanks – probiner Aug 11 '15 at 22:37
  • @DavidHeffernan I think I might be understanding what you mean with derivative now... maybe... I've made a simple function that returns the y coordinate of a "bezier curve"(?) And if I keep feeding it self, I go from linear to something that starts to go really smooth on ends, the Numbers are the number of times I passed the float through the function. Image: http://i.imgur.com/hpk1ntf.png – probiner Aug 12 '15 at 02:30

2 Answers2

-1

Ok, so I remember I've done such thing in nodes before so might give it a shot in code. Here you can call several curves from curveFilter function.

curve image

So I pass a normal space float, choose a curve and maybe a control value and it returns a normal space float but respecting the curve shape.

Thanks

Code in action: http://repl.it/BBTY

In your IDE with pylab you can add the following to see the curve being drawn:

size = 100
lin = [i/float(size) for i in xrange(size+1)]
smooth = [curveFilter(x,2,2) for x in lin]

import pylab
pylab.plot(lin, smooth)
pylab.show()

I don't know if this is the best way to do it but it's working for me in a way. Maybe there are better curve shapes, more flat, that only smooth more in the end points?

probiner
  • 91
  • 9
-2

Well at least I managed to do the LUT, using an exported 3d file, it generated the smoothed list for me like so: objfile And then I used it in the code below that any normalized value I set in Blend is returns the matching smooth position.

http://repl.it/BBMM

A curve like that is a bezier curve? Is that the calculation I'm looking for?

probiner
  • 91
  • 9
  • Is this the answer to your question? If so, do you expect anybody else to answer? I think this is not an answer. Perhaps you meant to edit this content into your question. – David Heffernan Aug 11 '15 at 08:03
  • @DavidHeffernan I seriously don't understand why every time I pose a question in SO it reveals like a knee-jerk palace with down-votes and not much help most times. This answer, answers to the LUT proposition. The image just shows how I got the smoothed list. but the code link to repl.it shows how the code runs with the two lists. So I do answer to my own question in part. Next I'll post a question to the actual calculation of values and not just using a LUT. – probiner Aug 11 '15 at 21:41