Create a mesh within a triangle and interpolate within this mesh
3 次查看(过去 30 天)
显示 更早的评论
Hi folks,
I have a 2D triangle and corrosponding data values at each vertices. I want to generate a mesh within the triangle, interpolate my data across that mesh, then average out all the values to get a mean across the triangles surface. I have a fairly clunky solution and was wondering if there was something more streamlined available. Here's what I have:
coord=[470590,7333138;470642,7333275;470643,7333214]; % coordinates of the triangle (these are eastings and northings)
v=[1 2 3] ; % data values at each vertices of the triangle
x=coords(:,1);
y=coords(:,2);
F=scatteredInterpolant(x,y,v);
% now I generate the query coordinates using a function from exchange called "generate triangle mesh" where X and Y are the coordinates of the new points
n=10 % number of interpolant points I want to generate in the triangle
[X,Y]=Triangle_Mesh(coords(1,:),coords(2,:),coords(3,:),n); % the function
vq=F(X,Y); % interpolates in the triangle which I can then average out
Thanks
Dirk
采纳的回答
Bruno Luong
2023-9-22
coords=[470590,7333138;470642,7333275;470643,7333214];
v=[1 2 3] ; % data values at each vertices of the triangle
x=coords(:,1);
y=coords(:,2);
% Replace your mesh data
[X,Y]=meshgrid(linspace(min(x),max(x),10),linspace(min(y),max(y),10));
F=scatteredInterpolant(x,y,v(:));
vq=F(X,Y) % interpolates in the triangle which I can then average out
% Compute vq directly without the need of scatteredInterpolant
vq = reshape((([X(:) Y(:) ones(numel(X),1)] / [coords, [1;1;1]]) * v(:)), size(X))
1 个评论
Bruno Luong
2023-9-22
编辑:Bruno Luong
2023-9-22
Alternative way
% Compute vq directly without the need of scatteredInterpolant
c = [coords, ones(3,1)] \ v(:);
vq = c(1)*X + c(2)*Y + c(3)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!