We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Interpolate Value Function using Splines
Page Index Toggle Pages: 1
Interpolate Value Function using Splines (Read 1562 times)
Interpolate Value Function using Splines
Aug 30th, 2005, 12:00pm
 
Hello, I would like to have a simple function
that allows to get interpolated values out
of 3 given parameters. Interpolated should
happen with some spline/curve function and
no simple linear one:

v = interpolate (a,b,c, step);

a,b,c   floats

step    ranges from 0 (equals a) to 1 (equals c) and
       allows outputting interpolated values in the
       range ... 0.5 would logically output b

I know this isn't that hard, but since my math
is faded, for many of you, it would be a snap ...

Thanks for helping, Rob
Re: Interpolate Value Function using Splines
Reply #1 - Aug 30th, 2005, 4:17pm
 
sure, the functions are even called curve() and bezier():
http://processing.org/reference/curve_.html
http://processing.org/reference/bezier_.html
Re: Interpolate Value Function using Splines
Reply #2 - Aug 31st, 2005, 2:23am
 
Right, but I think rs3d is asking for a way to do this with numbers, not drawing. I've not tested this, but I'd imagine it would do the trick:

Code:
float interpolate(float a, float b, float c, float step) {
if(step <= 0.5) {
step *= 2;
return (b * step) + (a * (1 - step));
} else {
step = (step - 0.5) * 2;
return (c * step) + (b * (1 - step));
}
}
Re: Interpolate Value Function using Splines
Reply #3 - Aug 31st, 2005, 12:11pm
 
Thanks rgovostes, you are right ... but the
thing is, it doesn't interpolate smoothly
with a bspline or cubic function. This just
creates a linear interpolation ...

Thanks, RS
Re: Interpolate Value Function using Splines
Reply #4 - Aug 31st, 2005, 1:46pm
 
You might have a look at Robert Penner's easing functions: http://www.robertpenner.com/easing/ - it's pretty easy to convert them from ActionScript to Java and I'm pretty sure that they'll do exactly what you need.
Re: Interpolate Value Function using Splines
Reply #5 - Aug 31st, 2005, 3:15pm
 
sorry, linked to the wrong functions, it's curvePoint and bezierPoint:
http://processing.org/reference/curvePoint_.html
http://processing.org/reference/bezierPoint_.html
(they used to be just called curve and bezier in earlier alphas.. i can't keep my own api straight)

they evaluate a bezier (a cubic spline) or catmull-rom curve at a point, and can be used for easing functions like was being asked for. don't be fooled by the fact that the reference describes it in terms of evaluating curves at x and y points and drawin them.. you'll notice that the x and y dimensions have to be evaluated separately, because this is just a 1D curve function.
Re: Interpolate Value Function using Splines
Reply #6 - Aug 31st, 2005, 9:22pm
 
Thanks, the Robert Penner ones are great inspirations, too!
Page Index Toggle Pages: 1