Identifying This Curve Algorithm?

64 Views Asked by At

I have some code and i don't know what algorithm it is using to generate the curve using control points (similar to how Bezier works as an example).

float Blend(float a, float b, float c, float d, float percent)
{
    // this computes one component
    // for points p_0, p_1, p_2, p_3 then the variables a,b,c,d
    // correspond to the x/y/z components for those points

    const float kThird     = 1.0f / 3.0f;
    const float kTwoThirds = 2.0f / 3.0f;

    float dc = d - c;
    float cb = c - b;
    float ba = b - a;

    float e = dc - cb;
    float f = cb - ba;

    float g;

    // e - f
    // = ((d - c) - (c - b)) - ((c - b) - (b - a))
    // = -a + 3b - 3c + d

    g = e - f;
    g = g * (percent - kTwoThirds);

    g = g + f;
    g = g * (percent - kThird) / kTwoThirds;

    g = g + ba;
    g = g * percent / kThird;

    g = g + a;

    return g; // computes one component at a time

}

Code is in C++, should be easy enough to read, if not let me know.

That's the code, can't really figure out which algorithm it is.

https://i.stack.imgur.com/dcoKJ.png

The above picture is the curve generated using control points:

  • (0, 0)
  • (0, 1)
  • (1, 1)
  • (1, 0)

I would like to know the name of this curve algorithm if anyone can identify it.

1

There are 1 best solutions below

2
On BEST ANSWER

It looks like it's doing Newton interpolation over the points $(0, a)$, $(\frac{1}{3}, b)$, $(\frac{2}{3}, c)$ and $(1, d)$ and evaluating at $p$ if I'm not mistaken, where $p$ is percent.