osu.Framework/MathUtils/Interpolation.cs
/// <summary>
/// Calculates the Lagrange basis polynomial for a given set of x coordinates. Used as a helper function to compute Lagrange polynomials.
/// </summary>
/// <param name="points">An array of coordinates. No two x should be the same.</param>
/// <param name="base">The index inside the coordinate array which polynomial to compute.</param>
/// <param name="time">The x coordinate to calculate the basis polynomial for.</param>
Calculates the Lagrange basis polynomial for a given set of x coordinates. Used as a helper function to compute Lagrange polynomials.
Calculates the Lagrange basis polynomial for a given set of x coordinates . Used as a helper function to compute Lagrange polynomials .
public static double LagrangeBasis(ReadOnlySpan<Vector2> points, int @base, double time)
        {
            double product = 1;
            for (int i = 0; i < points.Length; i++)
                if (i != @base)
                    product *= (time - points[i].X) / (points[@base].X - points[i].X);
            return product;
        }
public static double LagrangeBasis ( ReadOnlySpan < Vector2 > points , int @base , double time ) { double product = 1 ; for ( int i = 0 ; i < points . Length ; i ++ ) if ( i != @base ) product *= ( time - points [ i ] . X ) / ( points [ @base ] . X - points [ i ] . X ) ; return product ; }
Calculates the Lagrange basis polynomial for a given set of x coordinates.
Calculates the Lagrange basis polynomial for a given set of x coordinates .
points
ReadOnlySpan<Vector2>
An array of coordinates. No two x should be the same.
An array of coordinates . No two x should be the same .
@base
int
time
double
The x coordinate to calculate the basis polynomial for.
The x coordinate to calculate the basis polynomial for .
base
The index inside the coordinate array which polynomial to compute.
The index inside the coordinate array which polynomial to compute .