简体   繁体   English

用ILnumerics和c#绘制3d表面

[英]Plot 3d surface with ILnumerics and c#

I have used this code: 我使用了以下代码:

    private void ilPanel1_Load(object sender, EventArgs e)
    {    using (ILScope.Enter())
        {
            ILArray<float> X = new float[] { 0, 0, 1, 1, 2.5F, -2.6F, 5, 9, 1, 38 };
            ILArray<float> Y = new float[] { 1, 0, 1, 0, 1.5F,  0.5F, 5, 9, 1, 39 };
            ILArray<float> Z = new float[] { 0, 0, 1, 1, 0.4F, -0.2F, 5, 9, 1, 39 };
            X = X.Reshape(2,5);
            Y = Y.Reshape(2,5);
            Z = Z.Reshape(2,5);
            ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
                new ILSurface(Z, colormap: Colormaps.Cool) {
                    Colors = 1.4f  ,Children = { new ILColorbar() }
                }
            });
        }
    }

This produces: 这将产生:

在此处输入图片说明

However I checked this question and tried to adapt deprecated ILnumerics solution (as I did not find other c# code), but still do not get it, every coordinate (Z,X and Y) corresponds to one slice (mxn) in the array. 但是我检查了这个问题,并尝试采用不推荐使用的ILnumerics解决方案 (因为我没有找到其他c#代码),但仍然没有得到它,每个坐标(Z,X和Y)都对应于数组中的一个切片(mxn)。 So it is necesarry to reshape data. 因此,有必要重塑数据。

this part is the problem: 这部分是问题:

            X = X.Reshape(2,5);
            Y = Y.Reshape(2,5);
            Z = Z.Reshape(2,5);

If I do not give correct size, program fails, so in example I have 10 elements on each vector, so when resahping I would put 2,5 which multiplied are 10?... 如果我没有给出正确的大小,则程序将失败,因此在示例中,每个向量上有10个元素,因此在重新分配时,我会将2,5乘以10?

What about case I have 11 elements as if I put 2,5 on reshape I get error? 如果我有11个元素,好像我在重塑上放了2,5时出现错误怎么办?

What to do? 该怎么办?

I have tried using X = X.Reshape(11); 我试过使用X = X.Reshape(11); but It fails... if I use X = X.Reshape(10); 但是失败了...如果我使用X = X.Reshape(10); it just do not draw anything 它只是不画任何东西

surfaces plot meshes. 曲面绘制网格。 one must provide a mesh in order to give the surface the chance to understand how to connect the points, which points are meant to be neighbors. 必须提供一个网格,以便使曲面有机会了解如何连接这些点,这些点是相邻的。

the reshape should not be a problem since the original data must represent the points for a mesh/matrix anyway. 整形应该没有问题,因为无论如何原始数据都必须代表网格/矩阵的点。 so the reshape to that matrix will certainly work. 因此重塑该矩阵肯定会起作用。

reshape(10) creates a vector of length 10. since vectors do represent a line at most but not an area - nothing is drawn. reshape(10)创建一个长度为10的向量,因为向量的确最多代表一条线,但不代表一条区域,因此未绘制任何内容。 remember: surfaces draw meshes or matrices. 切记:曲面绘制网格或矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM