Possible spline substitute: Sigmoid function

I found myself thinking about those pretty cable-like lines often used in node editors:
(e.g. Blender)

Now, they’re almost certainly implemented via some kind of spline, but for some probably masochistic reason I realized they looked a lot like a sigmoid curve.

It’s probably been [derived?] before, but this is what I came up with: (excuse the crappy TeX output)

Where f(x) is the curve between points (X1, Y1) and (X2, Y2) and s is a number probably somewhere between 10 and 20, which I will call ‘slack.’
Play with it in the desmos link to see exactly what it does. I could probably refine the equation to handle lower values of slack better, but meh.

https://www.desmos.com/calculator/bd1v5ylpth

Someone might actually find this useful, or at least be now enlightened with the Sigmoid function.

Demo: http://pastebin.java-gaming.org/3f49244562010

Nice! I’m gonna give these a shot when I get back to doing editor work.

(non-optimized, specialized, etc) parametric interpretation on t ∈ [0, 1] in case someone doesn’t want to have to rearrange it:

public static Point2D.Double sigmoidInterp(double t, Point p1, Point p2, double s) {
    double x = (1 - t) * p1.getX() + t * p2.getX(); // lerp
    return new Point2D.Double(x, p1.y + (p2.y - p1.y) / (1 + Math.exp(-s * (t - .5))));
}

There isn’t one S-curve. There a many. And one is Hermite.

And it’s probably better, I know. I chose logistic as the basis.

i filter sigmoid a bit more simple, but pretty much the same : [icode]y = 1.0/( 1.0 + StrictMath.exp(-(( x*2 - 1 )*sharpness)))[/icode] while [icode]x[/icode] is [icode]0…1[/icode]. [icode]sharpness[/icode] of 5 to 6 looks nice :slight_smile: