Create a mesh within a triangle and interpolate within this mesh

4 次查看(过去 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
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
vq = 10×10
1.0000 1.3524 1.7047 2.0571 2.4095 2.7619 3.1142 3.4666 3.8190 4.1714 0.7654 1.1178 1.4701 1.8225 2.1749 2.5272 2.8796 3.2320 3.5844 3.9367 0.5308 0.8831 1.2355 1.5879 1.9403 2.2926 2.6450 2.9974 3.3498 3.7021 0.2962 0.6485 1.0009 1.3533 1.7057 2.0580 2.4104 2.7628 3.1151 3.4675 0.0615 0.4139 0.7663 1.1187 1.4710 1.8234 2.1758 2.5282 2.8805 3.2329 -0.1731 0.1793 0.5317 0.8841 1.2364 1.5888 1.9412 2.2935 2.6459 2.9983 -0.4077 -0.0553 0.2971 0.6494 1.0018 1.3542 1.7066 2.0589 2.4113 2.7637 -0.6423 -0.2899 0.0625 0.4148 0.7672 1.1196 1.4719 1.8243 2.1767 2.5291 -0.8769 -0.5245 -0.1722 0.1802 0.5326 0.8850 1.2373 1.5897 1.9421 2.2944 -1.1115 -0.7591 -0.4068 -0.0544 0.2980 0.6503 1.0027 1.3551 1.7075 2.0598
% Compute vq directly without the need of scatteredInterpolant
vq = reshape((([X(:) Y(:) ones(numel(X),1)] / [coords, [1;1;1]]) * v(:)), size(X))
vq = 10×10
1.0000 1.3524 1.7047 2.0571 2.4095 2.7619 3.1142 3.4666 3.8190 4.1714 0.7654 1.1178 1.4701 1.8225 2.1749 2.5272 2.8796 3.2320 3.5844 3.9367 0.5308 0.8831 1.2355 1.5879 1.9403 2.2926 2.6450 2.9974 3.3498 3.7021 0.2962 0.6485 1.0009 1.3533 1.7057 2.0580 2.4104 2.7628 3.1151 3.4675 0.0615 0.4139 0.7663 1.1187 1.4710 1.8234 2.1758 2.5282 2.8805 3.2329 -0.1731 0.1793 0.5317 0.8841 1.2364 1.5888 1.9412 2.2935 2.6459 2.9983 -0.4077 -0.0553 0.2971 0.6494 1.0018 1.3542 1.7066 2.0589 2.4113 2.7637 -0.6423 -0.2899 0.0625 0.4148 0.7672 1.1196 1.4719 1.8243 2.1767 2.5291 -0.8769 -0.5245 -0.1722 0.1802 0.5326 0.8850 1.2373 1.5897 1.9421 2.2944 -1.1115 -0.7591 -0.4068 -0.0544 0.2980 0.6503 1.0027 1.3551 1.7075 2.0598
  1 个评论
Bruno Luong
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 CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by