2D value interpolation of a polygon
49 views (last 30 days)
Show older comments
Hi,
We are trying to interpolate an area in the shape of a polygon, based on the values of 3 different edges (E4,E6,E2). See figure_geometry in which the middle area is the one to be interpolated and the other 3 rectangles contain values varying as a function of the y coordinate.
We made a mesh of the problem, see figure_mesh.
We assigned values to the nodes of the polygon at the edges that are known (interfaces with the rectangles). We're however struggling now to execute an interpolation on the polygon.
Here is the code so far:
clear all
close all
model1 = createpde;
rect1 = [3
4
0
2
2
0
0
0
6
6];
rect2 = [3
4
14
16
16
14
0
0
6
6];
rect3 = [3
4
5
11
11
5
-6
-6
-4
-4];
gd = [rect1,rect2,rect3];
ns = char('rect1','rect2','rect3');
ns = ns';
sf = '(rect1+rect2+rect3)';
[dl,bt] = decsg(gd,sf,ns);
geometryFromEdges(model1,dl);
specifyCoefficients(model1,'m',0,...
'd',0,...
'c',1,...
'a',0,...
'f',0);
applyBoundaryCondition(model1,'dirichlet','Edge',[10,11,4],'u',60);
applyBoundaryCondition(model1,'dirichlet','Edge',[7,8,2],'u',-60);
%% Model 2 = polygon
model2 = createpde;
poly1 = [2
6
2
5
11
14
14
2
0
-4
-4
0
6
6
0];
gd2 = [poly1];
ns2 = char('poly1');
ns2 = ns2';
sf2 = '(poly1)';
f_vector = zeros(17,1);
sixty_vector = repmat(60,17,1);
[dl2,bt2] = decsg(gd2,sf2,ns2);
geometryFromEdges(model2,dl2);
specifyCoefficients(model2,'m',0,...
'd',0,...
'c',1,...
'a',0,...
'f',0);
%% plotting figures
figure(1) % overall geometry
pdegplot(model1,'FaceLabels','on')
hold on
pdegplot(model2,'EdgeLabels','on','FaceLabels','on')
xlim([0 16])
ylim([-6 6])
figure(2) % mesh for all
mesh = generateMesh(model1,'Hmax',1);
pdemesh(mesh)
hold on
mesh2 = generateMesh(model2,'Hmax',1);
pdemesh(mesh2)
axis equal
results_pde = solvepde(model1);
results = abs(results_pde.NodalSolution);
%% Figure outcome
figure(3) % solve linear for 3 rectangles
pdeplot(model1,'XYData', results)
hold on
results_pde2 = solvepde(model2);
results2 = results_pde2.NodalSolution;
pdeplot(model2,'XYData', results2);
axis equal
%% New attempt
Nf_f4 = findNodes(mesh2,'region','Face',1); % nodes of Face 4
values_f4 = results2(Nf_f4);
values_f4 = NaN(1,length(values_f4));
Nf_edge6_f4 = flip(findNodes(mesh2,'region','Edge',6));
Nf_edge4_f4 = flip(findNodes(mesh2,'region','Edge',4));
Nf_edge2_f4 = flip(findNodes(mesh2,'region','Edge',2));
Nf_edge6 = findNodes(mesh,'region','Edge',6); % nodes of E6
values_E6 = results(Nf_edge6);
Nf_edge4 = findNodes(mesh,'region','Edge',1); % nodes of E4
values_E4 = results(Nf_edge4);
Nf_edge3 = findNodes(mesh,'region','Edge',3); % nodes of E6
values_E3 = results(Nf_edge3);
for i = 1:length(values_E6)
values_f4(Nf_edge6_f4(i)) = values_E6(i);
values_f4(Nf_edge4_f4(i)) = values_E4(i);
values_f4(Nf_edge2_f4(i)) = values_E3(i);
end
Interpolation_coordinates = mesh2.Nodes(:,Nf_f4);
[X,Y] = meshgrid(Interpolation_coordinates(1,:),Interpolation_coordinates(2,:));
values_f4 = repelem(values_f4,[length(values_f4)],[1]);
% How to fill matrix 'values_f4' with the interpolated values?
0 Comments
Answers (0)
See Also
Categories
Find more on Geometry and Mesh in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!