【问题标题】:Plot a simple ILNumerics surface specified by X, Y, Z coordinates?绘制由 X、Y、Z 坐标指定的简单 ILNumerics 曲面?
【发布时间】:2014-07-17 15:53:49
【问题描述】:

我想通过指定曲面的角来绘制 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);
    }

【问题讨论】:

  • 代码编译,运行没有错误?请描述预期的行为以及观察到的结果有何偏差?
  • 是的,它编译并运行,但显示的表面是错误的。显示的表面是一个矩形,但它应该是一个具有以下 4 个角 (X, Y, Z) 的多边形:(0, 0.5, 1), (0, 1, 1), (0, 0.75, 0.75),和 (0, 1, 0.5)

标签: c# ilnumerics


【解决方案1】:

这似乎有效:

    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 个就足够了)。

【讨论】:

    猜你喜欢
    • 2013-09-20
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    相关资源
    最近更新 更多