ILNumerics在特定位置绘制一架飞机

我正在玩ILNumerics API并开始在多维数据集中绘制几个点。 然后我通过这些点计算出一个回归平面。 现在我想在相同的场景图中绘制平面,但只有与点云相同的大小。

我得到了平面的参数(a,b,c):f(x,y)= a * x + b * y + c; 我知道只有z对绘制一个平面很有意思,但我不知道如何将右坐标传递给场景,这样平面尺寸大小与点的最大和最小面积大小相同。

你们能给我一个简单的例子来描绘一架飞机和一点点建议如何设置那架飞机的界限吗?

这是我到目前为止所得到的:

private void ilPanel1_Load(object sender, EventArgs e) { // get the X and Y bounds and calculate Z with parameters // plot it! var scene = new ILScene { new ILPlotCube(twoDMode: false) { new ILSurface( ??? ) { } } }; // view angle etc scene.First().Rotation = Matrix4.Rotation( new Vector3(1f, 0.23f, 1), 0.7f); ilPanel1.Scene = scene; } 

我希望有人可以帮助我…提前谢谢!

您可以获取plotcube.Plots组的限制,并从中获取边界框中的坐标。 这为您提供了飞机的最小和最大x和y坐标。 通过评估平面方程,使用它们来获得相应的z值。

获得平面的x,y和z后,使用ILSurface绘制平面。

如果您需要更多帮助,我可以尝试添加一个示例。

@Edit:以下示例绘制通过3个任意点的平面。 通过平面函数zEval计算平面方向和位置。 它的系数a,b,c在这里由3个(具体)点计算。 您必须在此计算自己的方程系数。

该平面用表面实现。 人们可以采用在’P’中计算的4个坐标,并使用ILTriangleFan和ILLineStrip来创建平面和边界。 但是表面已经有了Fill和Wireframe,所以我们将其作为一种快速解决方案。

 private void ilPanel1_Load(object sender, EventArgs e) { // 3 arbitrary points float[,] A = new float[3, 3] { { 1.0f, 2.0f, 3.0f }, { 2.0f, 2.0f, 4.0f }, { 2.0f, -2.0f, 2.0f } }; // construct a new plotcube and plot the points var scene = new ILScene { new ILPlotCube(twoDMode: false) { new ILPoints { Positions = A, Size = 4, } } }; // Plane equation: this is derived from the concrete example points. In your // real world app you will have to adopt the weights a,b and c to your points. Func zEval = (x, y) => { float a = 1, b = 0.5f, c = 1; return a * x + b * y + c; }; // find bounding box of the plot contents scene.Configure(); var limits = scene.First().Plots.Limits; // Construct the surface / plane to draw // The 'plane' will be a surface constructed from a 2x2 mesh only. // The x/y coordinates of the corners / grid points of the surface are taken from // the limits of the plots /points. The corresponding Z coordinates are computed // by the zEval function. So we give the ILSurface constructor not only Z coordinates // as 2x2 matrix - but an Z,X,Y Array of size 2x2x3 ILArray P = ILMath.zeros(2, 2, 3); Vector3 min = limits.Min, max = limits.Max; P[":;:;1"] = new float[,] { { min.X, min.X }, { max.X, max.X } }; P[":;:;2"] = new float[,] { { max.Y, min.Y }, { max.Y, min.Y } }; P[":;:;0"] = new float[,] { { zEval(min.X, max.Y) , zEval(min.X, min.Y) }, { zEval(max.X, max.Y) , zEval(max.X, min.Y) }, }; // create the surface, make it semitransparent and modify the colormap scene.First().Add(new ILSurface(P) { Alpha = 0.6f, Colormap = Colormaps.Prism }); // give the scene to the panel ilPanel1.Scene = scene; } 

这将创建一个类似于这个的图像:

使用ILNumerics进行平面穿越

@ Edit2:你问过,如何在添加曲面时禁用绘图立方体的自动缩放:

 // before adding the surface: var plotCube = scene.First(); plotCube.AutoScaleOnAdd = false; 

或者,您可以手动设置多维数据集的限制:

 plotCube.Limits.Set(min,max); 

您可能也希望禁用某些鼠标交互,因为它们允许用户以类似(不需要的)方式重新缩放多维数据集:

 plotCube.AllowZoom = false; // disables the mouse wheel zoom plotCube.MouseDoubleClick += (_,arg) => { arg.Cancel = true; // disable the double click - resetting for the plot cube };