绘制由X,Y,Z坐标指定的简单ILNumerics曲面?

时间:2014-07-16 16:21:41

标签: c# ilnumerics

我想通过指定曲面的角来绘制ILNumerics 3D曲面。在下面的代码中,我将这些角调用为point0,point1,point2和point3。下面的代码不起作用,我不知道为什么。另外,我不明白为什么我需要将我的X,Y和Z数据转换成矩阵,但在所有的例子中我都能找到类似的东西。请帮帮我。

    private void ilPanel1_Load(object sender, EventArgs e)
    {
        ILPlotCube pc = new ILPlotCube(twoDMode: false);
        ILScene scene = new ILScene { pc };

        ILArray<float> point0 = new float[] { 0, 0.5f, 1 };
        ILArray<float> point1 = new float[] { 0, 1, 1 };
        ILArray<float> point2 = new float[] { 0, 0.75f, 0.75f };
        ILArray<float> point3 = new float[] { 0, 1, 0.5f };

        ILArray<float> X = new float[] { (float)point0[0], (float)point1[0], (float)point2[0], (float)point3[0] };
        ILArray<float> Y = new float[] { (float)point0[1], (float)point1[1], (float)point2[1], (float)point3[1] };
        ILArray<float> Z = new float[] { (float)point0[2], (float)point1[2], (float)point2[2], (float)point3[2] };


        // compute X and Y pointinates for every grid point
        ILArray<float> YMat = 1; // provide YMat as output to meshgrid
        ILArray<float> XMat = ILMath.meshgrid(X, Y, YMat); // only need mesh for 2D function here
        ILArray<float> ZMat = ILMath.zeros<float>(Y.Length, X.Length);
        ZMat["0;:"] = Z;
        ZMat["1;:"] = Z;
        ZMat["2;:"] = Z;
        ZMat["3;:"] = Z;

        // preallocate data array for ILSurface: X by Y by 3
        // Note the order: 3 matrix slices of X by Y each, for Z,X,Y pointinates of every grid point
        ILArray<float> XYZ = ILMath.zeros<float>(Y.Length, X.Length, 3);


        XYZ[":;:;0"] = ZMat;
        XYZ[":;:;1"] = XMat; // X pointinates for every grid point
        XYZ[":;:;2"] = YMat; // Y pointinates for every grid point


        pc.Add(new ILSurface(XYZ));

        ilPanel1.Scene = scene;
        ilPanel1.Scene.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(1f, 0.23f, 1f), 0.7f);
    }

1 个答案:

答案 0 :(得分:0)

这似乎有效:

    private void ilPanel1_Load(object sender, EventArgs e)
    {
        ILPlotCube pc = new ILPlotCube(twoDMode: false);
        ILScene scene = new ILScene { pc };

        ILArray<float> point0 = new float[] { 0, 0.5f, 1 };
        ILArray<float> point1 = new float[] { 0, 1, 1 };
        ILArray<float> point2 = new float[] { 0, 0.75f, 0.75f };
        ILArray<float> point3 = new float[] { 0, 1, 0.5f };

        ILArray<float> XMat = ILMath.zeros<float>(2, 2);
        ILArray<float> YMat = ILMath.zeros<float>(2, 2);
        ILArray<float> ZMat = ILMath.zeros<float>(2, 2);
        XMat["0;0"] = point0[0];
        XMat["0;1"] = point1[0];
        XMat["1;0"] = point2[0];
        XMat["1;1"] = point3[0];

        YMat["0;0"] = point0[1];
        YMat["0;1"] = point1[1];
        YMat["1;0"] = point2[1];
        YMat["1;1"] = point3[1];

        ZMat["0;0"] = point0[2];
        ZMat["0;1"] = point1[2];
        ZMat["1;0"] = point2[2];
        ZMat["1;1"] = point3[2];

        // preallocate data array for ILSurface: X by Y by 3
        // Note the order: 3 matrix slices of X by Y each, for Z,X,Y pointinates of every grid point
        ILArray<float> XYZ = ILMath.zeros<float>(2, 2, 3);


        XYZ[":;:;0"] = ZMat;
        XYZ[":;:;1"] = XMat; // X pointinates for every grid point
        XYZ[":;:;2"] = YMat; // Y pointinates for every grid point


        pc.Add(new ILSurface(XYZ));

        ilPanel1.Scene = scene;
        ilPanel1.Scene.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(1f, 0.23f, 1f), 0.7f);
    }

然而,我选择的点不是很好,因为它们形成一个三角形(如果我想要一个三角形,指定4个点是多余的,3就足够了。)