Intercept Form in Code

I got the intercept form working in code. It’s pretty interesting to see the curve working in real-time and how the root’s Y value doesn’t affect it.

Intercept

Something I noticed while paying with the values is that setting a max height or modifying the value of ‘a’ directly have the same results, this can be used as optimization, since the following code:

    public float CurveIntercept(float x, Vector3 root1, Vector3 root2, float highestPoint)
    {
        float midXPoint = (root1.x + root2.x) / 2;
        float a = highestPoint / ((midXPoint - root1.x) * (midXPoint - root2.x));

        return a * ((x - root1.x) * (x - root2.x));
    }

Ends up with the exact same result as this one

    public float CurveIntercept(float x, float a, Vector3 root1, Vector3 root2)
    {
        return a * ((x - root1.x) * (x - root2.x));
    }


The main differences that I noticed are:

  • ‘a’ can be harder to manipulate because of how small the number has to be.
  • A max height is easier to understand.
  • Setting ‘a’ requires far less calculations.
  • It’s way harder to set perfect maximum height by directly modifying ‘a’.
  • To make a curve that goes down, ‘a’ needs to be positive, while a max height needs to be negative.

I think it all comes down to optimization vs not having to teach math to your designer :sweat_smile:

Privacy & Terms