您可以將plotcube.Plots組的極限值從邊界框中派生出來。這給你飛機的最小和最大x和y座標。使用它們通過評估平面方程來獲得相應的z值。
一旦你有x,y和z平面,就用它們和ILSurface來繪製平面。
如果您需要更多幫助,我可以嘗試添加示例。
@編輯:下面的例子通過3個任意點繪製一個平面。平面的方向和位置是通過平面函數zEval計算的。其係數a,b,c由3個(具體)點計算而來。你將不得不在這裏計算你自己的方程係數。
飛機是用表面實現的。也可以用'P'中計算出的4個座標,並使用ILTriangleFan和ILLineStrip創建平面和邊界。但表面已經有一個填充和一個線框,所以我們把它作爲一個快速解決方案。
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;
}
這將產生類似這樣的圖像:
![Plane Through Points with ILNumerics](https://i.stack.imgur.com/kaHrd.png)
@ EDIT2:你問,如何禁用情節立方體的自動縮放,同時將表面:
// before adding the surface:
var plotCube = scene.First<ILPlotCube>();
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
};
我會很感激的例子。 ..我知道如何繪製點,但我仍然不知道如何將正確的數組傳遞給ILSurface()方法......我用簡單的數據嘗試過它,但它從來沒有按照我想要的方式工作。在Matlab中,我需要生成x和y座標,如x = -1:0.01:1等,z只需要上面的公式和x和y範圍座標。你介意給一個簡單的例子嗎? – GeoGecco
由於您只想繪製一個平面,因此到曲面的數據將僅爲2x2x3:每個2x2切片將給出Z,X和Y(按此順序)的4個座標值。文件在這裏找到:http://ilnumerics.net/surface-plots.html –
對不起Haymo,但我不明白。爲什麼我需要每個座標軸有4個座標?那就是說我需要在ona數組中有3個2x2切片?類似於{{z z},{z z},{x x},{x x},{y y},{y y}}那對我沒有任何意義= D對不起。對我來說就像這樣:{{minRangeX maxRangeX},{minRangeY maxRangeY},{Z(XY)}}會有道理......你有一個12個座標的小例子嗎?對於annoying你很抱歉:D – GeoGecco