[英]Plot a simple ILNumerics surface specified by X, Y, Z coordinates?
我想通过指定曲面的角来绘制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);
}
这似乎可行:
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个就足够了)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.