Ejemplo n.º 1
0
    public static void bernstein_poly_01_values_test( )
    //****************************************************************************80
    //
    //  Purpose:
    //
    //    BERNSTEIN_POLY_01_VALUES_TEST tests BERNSTEIN_POLY_01_VALUES.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 February 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double b = 0;
        int    k = 0;
        int    n = 0;
        double x = 0;

        Console.WriteLine("");
        Console.WriteLine("BERNSTEIN_POLY_01_VALUES_TEST:");
        Console.WriteLine("  BERNSTEIN_POLY_01_VALUES returns values of ");
        Console.WriteLine("  the Bernstein Polynomials.");
        Console.WriteLine("");
        Console.WriteLine("     N     K       X      BERNSTEIN(N,K)(X)");
        Console.WriteLine("");
        int n_data = 0;

        for ( ; ;)
        {
            Bernstein.bernstein_poly_01_values(ref n_data, ref n, ref k, ref x, ref b);
            if (n_data == 0)
            {
                break;
            }
            Console.WriteLine("  "
                              + n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + k.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                              + x.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "  "
                              + b.ToString(CultureInfo.InvariantCulture).PadLeft(12) + "");
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Returns the point/vector at [u,v] of this surface patch
    /// </summary>
    /// <param name="t"></param>
    /// <returns></returns>
    public Vector3 GetPointAt(Vector2 uv)
    {
        Vector3 top = new Vector3(0, 0, 0);
        float   bot = 0;
        float   b1  = 0;
        float   b2  = 0;

        for (int u = 0; u < 4; u++)
        {
            for (int v = 0; v < 4; v++)
            {
                b1   = new Bernstein(u, 3, uv.x).calculate();
                b2   = new Bernstein(v, 3, uv.y).calculate();
                top += b1 * b2 * BezierPoints[u, v].Position * BezierPoints[u, v].Weight;
                bot += b1 * b2 * BezierPoints[u, v].Weight;
            }
        }
        return((1 / bot) * top);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Returns the point/vector at t for this spline
    /// </summary>
    /// <param name="t"></param>
    /// <returns></returns>
    public Vector3 GetPointAt(float t)
    {
        Vector3 top = new Vector3(0, 0, 0);
        float   bot = 0;
        float   b   = 0;

        for (int i = 0; i < controlPoints.Count; i++)
        {
            b    = new Bernstein(i, controlPoints.Count - 1, t).calculate();
            top += b * controlPoints.ElementAt(i).Position *controlPoints.ElementAt(i).Weight;
            bot += b * controlPoints.ElementAt(i).Weight;
        }

        for (int i = 0; i < controlPoints.Count; i++)
        {
            b = new Bernstein(i, controlPoints.Count - 1, t).calculate();
            //bot += b * controlPoints.ElementAt(i).Weight;
        }

        return((1 / bot) * top);
    }