ILNumerics绘制在特定位置的平面 [英] ILNumerics plot a plane at specific location

查看:226
本文介绍了ILNumerics绘制在特定位置的平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在与ILNumerics API玩耍,并开始在一个立方体绘制几个点。
然后,我计算出的回归平面的权利,通过这些点。
现在我想绘制飞机在同一场景中的情节,但仅比同尺寸的点云。

I'm currently playing around with the ILNumerics API and started to plot a few points in a cube. Then I calculated a regression plane right through those points. Now I'd like to plot the plane in the same scene plot but only with the same size than the point cloud.

我的的paramters平面(A,b,C):F(X,Y)= * X + b * Y + C;
我知道,只有z是对于绘制平面有趣的,但我有不知道如何通过正确的座标到现场,这样的平面尺寸大约比同尺寸的点的最大和最小面积。

I got the paramters of the plane (a,b,c): f(x,y) = a*x + b*y + c; I know that only z is interesting for plotting a plane but I've got no clue how pass the right coodinates to the scene so that the plane size is about the same size than the maximum and minimum area of the points.

难道你们给我策划一个平面和一个小suggetion如何设置飞机吧?

Could you guys give me a simple example of plotting a plane and a little suggetion how to set the bounds of that plane right?

下面是我走到这一步:

        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<ILPlotCube>().Rotation = Matrix4.Rotation(
            new Vector3(1f, 0.23f, 1), 0.7f);

        ilPanel1.Scene = scene; 
    }



我希望有人能帮助我...
谢谢前进!

I hope that someone can help me ... Thanks in advance !!!

推荐答案

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

You could take the Limits of the plotcube.Plots group and derive the coords from the bounding box from it. This gives you the min and max x and y coord for the plane. Use them to get the corresponding z values by evaluating you plane equation.

一旦你有X,Y和平面Z,使用他们ILSurface绘制平面。

Once you have x,y and z of the plane, use them with ILSurface to plot the plane.

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

If you need more help, I can try to add an example.

@Edit:下面的示例通过绘制任意3个点的平面。平面取向和位置是由一个平面功能zEval的帮助来计算。其系数a,b,c的这里从3(混凝土)点计算的。你将不得不在这里计算你自己的方程系数。

@ the following Example plots a plane through 3 arbitrary points. The planes orientation and position is computed by help of a plane function zEval. Its coefficients a,b,c are computed here from the 3 (concrete) points. You will have to compute your own equation coefficients here.

该飞机实现了表面。一不妨取4 COORDS在P计算,并且使用ILTriangleFan和ILLineStrip创建平面和边界。但表面已经配备了填充和线框,因此,我们拿这个作为一个快速的解决方案。

The plane is realized with a surface. One might as well take the 4 coords computed in 'P' and use an ILTriangleFan and an ILLineStrip to create the plane and the border. But the surface already comes with a Fill and a Wireframe, so we take this as a quick solution.

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<float, float, float> 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<ILPlotCube>().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<float> P = ILMath.zeros<float>(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<ILPlotCube>().Add(new ILSurface(P) {
        Alpha = 0.6f, 
        Colormap = Colormaps.Prism
    }); 
    // give the scene to the panel
    ilPanel1.Scene = scene;
}

这将创建一个与此相似的图像:

This would create an image similar to this one:

@ EDIT2:你问,如何禁用情节立方体的自动缩放同时加入了表面:

@ you asked, how to disable the automatic scaling of the plot cube while adding the surface:

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



另外,您也可以手动设置多维数据集的限制:

Alternatively, you can set the limits of the cube manually:

plotCube.Limits.Set(min,max); 

您可能会想禁用某些鼠标的交互,因为它们允许用户重新调整立方体类似的(无用?)的方式:

You probably will want to disable some mouse interaction as well, since they would allow the user to rescale the cube in a similar (unwanted?) way:

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

这篇关于ILNumerics绘制在特定位置的平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆