Beispiel #1
0
    //public Vector3 P (float u, float w)
    //{

    //    float wPow3 = Mathf.Pow(w, 3);
    //    float wPow2 = w * w;

    //    Vector3 A = points[0, 0] * wPow3 + points[0, 1] * wPow2 + points[0, 2] * w + points[0, 3];
    //    Vector3 B = points[1, 0] * wPow3 + points[1, 1] * wPow2 + points[1, 2] * w + points[1, 3];
    //    Vector3 C = points[2, 0] * wPow3 + points[2, 1] * wPow2 + points[2, 2] * w + points[2, 3];
    //    Vector3 D = points[3, 0] * wPow3 + points[3, 1] * wPow2 + points[3, 2] * w + points[3, 3];

    //    //Vector3 A = points[0, 0] * wPow3 + points[1, 0] * wPow2 + points[2, 0] * w + points[3, 0];
    //    //Vector3 B = points[0, 1] * wPow3 + points[1, 1] * wPow2 + points[2, 1] * w + points[3, 1];
    //    //Vector3 C = points[0, 2] * wPow3 + points[1, 2] * wPow2 + points[2, 2] * w + points[3, 2];
    //    //Vector3 D = points[0, 3] * wPow3 + points[1, 3] * wPow2 + points[2, 3] * w + points[3, 3];

    //    Vector3 result = A * Mathf.Pow(u, 3) + B * Mathf.Pow(u, 2) + C * u + D;

    //    return result;
    //}


    //public Vector3 P(float u, float w)
    //{

    //    float wPow3 = Mathf.Pow(w, 3);
    //    float wPow2 = w * w;

    //    // blendingMatrix
    //    Matrix4x4 B = new Matrix4x4();
    //    B.SetRow(0, new Vector4(-0.5f, 1.5f, -1.5f, 0.5f));
    //    B.SetRow(2, new Vector4(1f, -2.5f, 2f, -0.5f));
    //    B.SetRow(3, new Vector4(-0.5f, 0f, 0.5f, 0f));
    //    B.SetRow(4, new Vector4(0f, 1f, 0f, 0f));

    //    // transposedBlendingMatrix
    //    Matrix4x4 BT = B.transpose;

    //    Matrix4x4 P = new Matrix4x4();
    //    int i, j;
    //    P.SetRow(0, new Vector4(points[i + 3, j], points[i + 3, j+1], points[i + 3, j+2], points[i + 3, j+3]));
    //    P.SetRow(0, new Vector4(points[i + 2, j], points[i + 2, j+1], points[i + 2, j+2], points[i + 2, j+3]));
    //    P.SetRow(0, new Vector4(points[i + 1, j], points[i + 1, j+1], points[i + 1, j+2], points[i + 1, j+3]));
    //    P.SetRow(0, new Vector4(points[i + 0, j], points[i + 0, j+1], points[i + 0, j+2], points[i + 0, j+3]));

    //    Vector3 point = new Vector4(Mathf.Pow(u, 3), Mathf.Pow(u, 2), u, 1) * B;


    //    Vector3 A = points[0, 0] * wPow3 + points[0, 1] * wPow2 + points[0, 2] * w + points[0, 3];
    //    Vector3 B = points[1, 0] * wPow3 + points[1, 1] * wPow2 + points[1, 2] * w + points[1, 3];
    //    Vector3 C = points[2, 0] * wPow3 + points[2, 1] * wPow2 + points[2, 2] * w + points[2, 3];
    //    Vector3 D = points[3, 0] * wPow3 + points[3, 1] * wPow2 + points[3, 2] * w + points[3, 3];

    //    //Vector3 A = points[0, 0] * wPow3 + points[1, 0] * wPow2 + points[2, 0] * w + points[3, 0];
    //    //Vector3 B = points[0, 1] * wPow3 + points[1, 1] * wPow2 + points[2, 1] * w + points[3, 1];
    //    //Vector3 C = points[0, 2] * wPow3 + points[1, 2] * wPow2 + points[2, 2] * w + points[3, 2];
    //    //Vector3 D = points[0, 3] * wPow3 + points[1, 3] * wPow2 + points[2, 3] * w + points[3, 3];

    //    Vector3 result = A * Mathf.Pow(u, 3) + B * Mathf.Pow(u, 2) + C * u + D;

    //    return result;
    //}

    public Vector3 P(float u, float w)
    {
        Vector3 P0 = CubicBezier.P(points[0, 0], points[0, 1], points[0, 2], points[0, 3], w);
        Vector3 P1 = CubicBezier.P(points[1, 0], points[1, 1], points[1, 2], points[1, 3], w);
        Vector3 P2 = CubicBezier.P(points[2, 0], points[2, 1], points[2, 2], points[2, 3], w);
        Vector3 P3 = CubicBezier.P(points[3, 0], points[3, 1], points[3, 2], points[3, 3], w);

        Vector3 result = CubicBezier.P(P0, P1, P2, P3, u);

        return(result);
    }