osu.Framework/MathUtils/Interpolation.cs
/// <summary>
/// Calculates the Barycentric weights for a Lagrange polynomial for a given set of coordinates. Can be used as a helper function to compute a Lagrange polynomial repeatedly.
/// </summary>
/// <param name="points">An array of coordinates. No two x should be the same.</param>
Calculates the Barycentric weights for a Lagrange polynomial for a given set of coordinates. Can be used as a helper function to compute a Lagrange polynomial repeatedly.
Calculates the Barycentric weights for a Lagrange polynomial for a given set of coordinates . Can be used as a helper function to compute a Lagrange polynomial repeatedly .
public static double[] BarycentricWeights(ReadOnlySpan<Vector2> points)
        {
            int n = points.Length;
            double[] w = new double[n];
            for (int i = 0; i < n; i++)
            {
                w[i] = 1;
                for (int j = 0; j < n; j++)
                    if (i != j)
                        w[i] *= points[i].X - points[j].X;
                w[i] = 1.0 / w[i];
            }
            return w;
        }
public static double [ ] BarycentricWeights ( ReadOnlySpan < Vector2 > points ) { int n = points . Length ; double [ ] w = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = 1 ; for ( int j = 0 ; j < n ; j ++ ) if ( i != j ) w [ i ] *= points [ i ] . X - points [ j ] . X ; w [ i ] = 1.0 / w [ i ] ; } return w ; }
Calculates the Barycentric weights for a Lagrange polynomial for a given set of coordinates.
Calculates the Barycentric weights for a Lagrange polynomial for a given set of 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 .