我想动态计算 Array 的元素,并在每次迭代后将这些点放在 ILNumerics 表单上。可能吗?
更新:
这是我的代码。
初始化 N:
private const int N = 20000000;
这是一个将数据存储在数组中然后将其发送到名为“Draw”的函数的函数
public void Calc()
{
float o = (float) Math.PI/6;
float lambda;
const float hLambda = 0.02f;
const float hAlpha = 0.02f;
float alpha = (float) Math.PI/36;
float[,] a;
int i = 0;
a = new float[N, 3];
for (alpha = (float) 0; alpha < 6.2832; alpha += hAlpha)
for (lambda = -1.8f; lambda <= 1.8f; lambda += hLambda)
for (var j = 0; j < 1000; j++)
{
float xPaint = X_Sphere(lambda, o, alpha);
float yPaint = Y_Sphere(lambda, o, alpha);
float zPaint = Z_Sphere(lambda, o, alpha);
if (j > 900)
{
a[i, 0] = zPaint;
a[i, 1] = yPaint;
a[i, 2] = xPaint;
i++;
}
o = Calculate(o, lambda, alpha);
}
Draw(a, false);
}
它是计算数据的函数:
public float Calculate(float o, float lambda, float alpha)
{
return (float) (lambda*Math.Sin(o + alpha));
}
在那里我将坐标从球面坐标转换为笛卡尔坐标:
public float X_Sphere(float r, float tetta, float a)
{
return (float) (r*Math.Sin(tetta)*Math.Cos(a));
}
public float Y_Sphere(float r, float tetta, float a)
{
return (float) (r*Math.Sin(tetta)*Math.Sin(a));
}
public float Z_Sphere(float r, float tetta, float a)
{
return (float) (r*Math.Cos(tetta));
}
private void Draw(float[,] obj, bool twodMode)
{
var cm = new ILColormap(Colormaps.Jet);
var scene = new ILScene();
var pc = new ILPlotCube();
var points = new ILPoints();
points.Positions = obj;
points.Size = 1f;
ILArray<float> Z = ILSpecialData.sincf(10000000, 3, 4);
var cmap = new ILColormap(Colormaps.Jet);
points.Colors = cmap.Map(Z).T;
points.Color = null;
pc.TwoDMode = false;
scene.Add(pc);
pc.Add(points);
pc.AllowRotation = true;
pc.AllowZoom = true;
scene.Screen.First<ILLabel>().Visible = false;
ilPanel1.Scene = scene;
}