Create a mesh within a triangle and interpolate within this mesh
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dirk
el 22 de Sept. de 2023
Editada: Bruno Luong
el 22 de Sept. de 2023
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 comentarios
Respuesta aceptada
Bruno Luong
el 22 de Sept. de 2023
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 comentario
Bruno Luong
el 22 de Sept. de 2023
Editada: Bruno Luong
el 22 de Sept. de 2023
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)
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!