[英]Interpolate 3d surface ilnumerics
我想使用C#插值曲面。 情況如下:
給出了一組x,y,z坐標。 現在,我想使用更精細的網格在這些點之間進行插值。 實際上,我想知道某個點上的z坐標,例如x = 2.2,y = 1.6 z = ??。
我可以使用MatLab求解插值,但是使用c#時卻無法成功。此外,我能夠用數字表示出曲面,並嘗試在其主頁上找到一些信息。
編輯:
我想我需要澄清一些事情-很抱歉提出我的問題
在這里,您可以看到我如何從一些點上繪制表面:
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() }
}
});
}
}
}
}
x和y坐標從0到5線性分布,z坐標具有二次形狀。 我想現在在某個x,y坐標處的z坐標值,例如x = 2.2,y = 1.6 z =? -這絕對不是我了解的重點。 因此,我認為用“更細”的網格插值曲面是個好主意,這樣我便可以讀出z坐標的值...
有不同的插值技術可供選擇。 我建議從雙線性插值開始:
http://en.wikipedia.org/wiki/Bilinear_interpolation
或將每個四邊形划分為兩個三角形並使用重心插值:
http://zh.wikipedia.org/wiki/Barycentric_coordinate_system_(數學)
您的函數的z坐標在以下行中計算:
ILArray<float> z = ILMath.meshgrid(R * R, R, y);
由於meshgrid實際上用於創建二維函數評估的X和Y坐標,因此只有R * R結果進入z。 在該行之后,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
顯然,z僅取決於x,通過生成的表面可以清楚地看出:
因此,z的值為:x * x。 或為您的特定示例:
x=2.2, y=1.6 z =4.84
編輯:如果基礎函數未知,則可以
當前,ILNumerics中沒有相應的功能(如“ interp2”)。 但是,在您的情況下-僅需要對一個點進行插值(?),則可以找到相鄰的網格點並使用一種常見的插值方法。
編輯 :隨着插值工具箱的發布,事情變得非常容易。 現在,您可以單行高速插入任何尺寸。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.