I want to draw an ILNumerics 3D surface by specifying the corners of the surface. In the code below I call these corners point0, point1, point2, and point3. The code below doesn't work and I don't know why. Also, I don't understand why I need convert my X, Y and Z-data into matrices, but in all the examples I could find they did something similar. Please help me.
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);
}
This seems to work:
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);
}
However, the points I chose as example are not so good because they form a triangle (if I want a triangle, it's redundant to specify 4 points, 3 is enough).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.