필터 지우기
필터 지우기

Create a mesh within a triangle and interpolate within this mesh

조회 수: 2 (최근 30일)
Dirk
Dirk 2023년 9월 22일
편집: Bruno Luong 2023년 9월 22일
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
  댓글 수: 2
KSSV
KSSV 2023년 9월 22일
Share the link for the fileexchange function.
Dirk
Dirk 2023년 9월 22일
Note that I put [X Y] as the coordinates but the coordinates are actually contained in X only

댓글을 달려면 로그인하십시오.

채택된 답변

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