简体   繁体   English

内插3d表面数字

[英]Interpolate 3d surface ilnumerics

I'd like to interpolate a surface using c#. 我想使用C#插值曲面。 The situation is the following: 情况如下:

A set of x,y,z coordinates is given. 给出了一组x,y,z坐标。 Now I d like to interpolate between those points using a finer grid. 现在,我想使用更精细的网格在这些点之间进行插值。 Actually I d like to know the z coordinate at a certain point, eg x=2.2, y=1.6 z =??. 实际上,我想知道某个点上的z坐标,例如x = 2.2,y = 1.6 z = ??。

I was able to solve the interpolation using MatLab, but was not successful while using c#.. Furthermore, I was able to plot surfaces with ilnumerics, and tried to find some information on their homepage. 我可以使用MatLab求解插值,但是使用c#时却无法成功。此外,我能够用数字表示出曲面,并尝试在其主页上找到一些信息。

EDIT: 编辑:

I think I need to clarify some things - sorry for the confusing way of asking my question 我想我需要澄清一些事情-很抱歉提出我的问题

here you can see how I draw the surface out of some points: 在这里,您可以看到我如何从一些点上绘制表面:

using System;
using System.Drawing;
using System.Windows.Forms;
using ILNumerics;
using ILNumerics.Drawing;
using ILNumerics.Drawing.Plotting; 

namespace Surface
{
   public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
      }

      private void ilPanel1_Load(object sender, EventArgs e)
      {
         using (ILScope.Enter())
         {
            ILArray<float>  R = ILMath.linspace<float>(0, 5, 5);
            ILArray<float> R1 = ILMath.linspace<float>(0, 25, 5);
            ILArray<float>  y = 1;
            ILArray<float>  x = ILMath.meshgrid(R, R, y);
            ILArray<float> z = ILMath.meshgrid(R * R, R, y);
            ILArray<float> Z = ILMath.zeros<float>(x.S[0], x.S[1], 3);

            Z[":;:;1"] = x;
            Z[":;:;2"] = y;
            Z[":;:;0"] = z;

             ilPanel1.Scene.Add(new ILPlotCube(twoDMode: false) {
                new ILSurface(Z, colormap: Colormaps.Cool) {
                    Colors = 1.4f * x * x * x + 0.13f * y * y,
                    Childs = { new ILColorbar() }
                }
            });
         }
      }
   }
}

The x and y coordinates are linearly distributed from 0 to 5 and the z coordinate has an quadratic shape. x和y坐标从0到5线性分布,z坐标具有二次形状。 I d like to now the value of the z coordinate at a certain x,y coordinate, eg x=2.2, y=1.6 z =?? 我想现在在某个x,y坐标处的z坐标值,例如x = 2.2,y = 1.6 z =? - which is definitely not a know point on my surface. -这绝对不是我了解的重点。 So I thought it would be a good idea to interpolate the surface with an "finer" grid, that I m able to read out the value of the z coordinate... 因此,我认为用“更细”的网格插值曲面是个好主意,这样我便可以读出z坐标的值...

There are different interpolation techniques to choose from. 有不同的插值技术可供选择。 I would suggest to start with Bilinear interpolation: 我建议从双线性插值开始:

http://en.wikipedia.org/wiki/Bilinear_interpolation http://en.wikipedia.org/wiki/Bilinear_interpolation

or divide every quad into two triangles and use barycentric interpolation: 或将每个四边形划分为两个三角形并使用重心插值:

http://en.wikipedia.org/wiki/Barycentric_coordinate_system_(mathematics) http://zh.wikipedia.org/wiki/Barycentric_coordinate_system_(数学)

The z coordinate of your function is computed in this line: 您的函数的z坐标在以下行中计算:

 ILArray<float> z = ILMath.meshgrid(R * R, R, y);

Since meshgrid is actually used to create the X and Y coordinates for 2 dimensional function evaluation, only the R * R result goes into z. 由于meshgrid实际上用于创建二维函数评估的X和Y坐标,因此只有R * R结果进入z。 After that line, x,y and z look as follows: 在该行之后,x,y和z如下所示:

x
<Single> [5,5]
[0]: 0,00000 1,25000 2,50000 3,75000 5,00000 
[1]: 0,00000 1,25000 2,50000 3,75000 5,00000 
[2]: 0,00000 1,25000 2,50000 3,75000 5,00000 
[3]: 0,00000 1,25000 2,50000 3,75000 5,00000 
[4]: 0,00000 1,25000 2,50000 3,75000 5,00000 

y
<Single> [5,5]
[0]: 0,00000 0,00000 0,00000 0,00000 0,00000 
[1]: 1,25000 1,25000 1,25000 1,25000 1,25000 
[2]: 2,50000 2,50000 2,50000 2,50000 2,50000 
[3]: 3,75000 3,75000 3,75000 3,75000 3,75000 
[4]: 5,00000 5,00000 5,00000 5,00000 5,00000 

z
<Single> [5,5]
[0]: 0,00000 1,56250 6,25000 14,06250 25,00000 
[1]: 0,00000 1,56250 6,25000 14,06250 25,00000 
[2]: 0,00000 1,56250 6,25000 14,06250 25,00000 
[3]: 0,00000 1,56250 6,25000 14,06250 25,00000 
[4]: 0,00000 1,56250 6,25000 14,06250 25,00000 

Obviously, z does only depend on x, which gets clear by the resulting surface: 显然,z仅取决于x,通过生成的表面可以清楚地看出:

表面

So, the value of z would be: x * x. 因此,z的值为:x * x。 Or for your specific example: 或为您的特定示例:

x=2.2, y=1.6 z =4.84

Edit: In case the underlying function is not known, you could either 编辑:如果基础函数未知,则可以

  • try to learn that function (using ridge_regression() or pinv()), or 尝试学习该功能(使用ridge_regression()或pinv()),或
  • interpolate from the data of the neighboring grid points. 从相邻网格点的数据进行插值。

There is currently no corresponding function (like 'interp2') in ILNumerics. 当前,ILNumerics中没有相应的功能(如“ interp2”)。 However, in your case - where only one single point needs to be interpolated (?), one can find the neighboring grid points and use one of the common interpolation methods. 但是,在您的情况下-仅需要对一个点进行插值(?),则可以找到相邻的网格点并使用一种常见的插值方法。

Edit : With the release of the interpolation toolbox things became significantly easier. 编辑 :随着插值工具箱的发布,事情变得非常容易。 You can now interpolate in any dimension in high speed and with a single line. 现在,您可以单行高速插入任何尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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