简体   繁体   中英

How to properly plot 3D surface with ZXYPositions in ilNumerics?

What I want to achieve?

I'm working on an evolutionary algorithm finding min/max of non-linear functions. I have fully functional WPF application, but there's one feature missing: 3D plots .

What is the problem?

To accomplish this I've started with free trial of ilNumerics which provide 3D data visualisation. It works completely fine with examples from documentation, but there's something what prevents me from plotting properly my own 3D graphs.

Visualising problem:

So, here is how it behaves at the moment

错误

Those are graphs of non-linear function: x1^4+x2^4-0.62*x1^2-0.62*x2^2

Left side : Contour achieved with OxyPlot

Right side : 3D graph achieved with ilNumerics

As you can see, OxyPlot contour is completely fine and 3D graph which I'm trying to plot with exactly same data is not proper at all.

How actual (not working) solution is done?

I'm trying to visualise 3D surface using points in space. ILNumerics has class called Surface which object I have to create in order to plot my graph. It has following constructor:

public Surface(InArray<float> ZXYPositions, InArray<float> C = null, Tuple<float, float> colorsDataRange = null, Colormap colormap = null, object tag = null);

where as you can see ZXYPositions is what I actually have problem with. Before instantiating Surface object I'm creating an Array like this:

int m = 0;
for (int i = 0; i < p; ++i)
{
       for (int j = 0; j < p; ++j)
       {
                sigma[m, 0] = (float)data[i, j];
                sigma[m, 1] = (float)xy[0][i];
                sigma[m, 2] = (float)xy[1][j];
                m++;
       }
}

where sigma[m, 0] = Z; sigma[m, 1] = X; sigma[m, 2] = Y;

And here's the problem. I cannot find any logical error in this approach. Here is code responsible for creating object which I'm passing to ilNumerics plot panel:

var scene = new PlotCube(twoDMode: false) {
    // add a surface
    new Surface(sigma) {
            // make thin transparent wireframes
            Wireframe = { Color = Color.FromArgb(50, Color.LightGray) },
            // choose a different colormap
            Colormap = Colormaps.Jet,
    }
};

Additionaly I want to say that sigma array is constructed properly, because I've printed out its values and they're definitely correct.

Plot only data points.

At the end I need to add, that when I'm not creating surface object and plot only data points it looks much more reasonable:

正确

But sadly it's not what I'm looking for. I want to create a surface with this data.

Good News!

I found the answer. Oddly almost evereything was fine.. I missunderstood just one thing. When I'm passing ZXYPositions argument to surface it can actually expect only Z data from me to plot graph correctly.

What did I changed to make it work

Two first for loops now looks like that:

sigma = data;

As you can see they're no longer loops, because sigma now contains only "solution" coordinates (which are Z coords), so I need to just assign data array to sigma.

Second part, where I'm creating Surface now looks like this:

var B = ILMath.tosingle(sigma);
var scene = new PlotCube(twoDMode: false) {
         // add a surface
         new Surface(B) {
                 // make thin transparent wireframes
                 Wireframe = { Color = Color.FromArgb(50, Color.LightGray) },
                 // choose a different colormap
                 Colormap = Colormaps.Jet,
         }
};
scene.Axes.XAxis.Max = (float)arguments[0].Maximum;
scene.Axes.XAxis.Min = (float)arguments[0].Minimum;
scene.Axes.YAxis.Max = (float)arguments[1].Maximum;
scene.Axes.YAxis.Min = (float)arguments[1].Minimum;
scene.First<PlotCube>().Rotation = Matrix4.Rotation(new Vector3(1f, 0.23f, 1), 0.7f);

Basically one thing which changed is scaling XY axes to proper values.

Final results

Here you have final results: 心

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM