Interpolation to arbitrary points on a patch plot
5 views (last 30 days)
Show older comments
Hi,
My question is, if I have all my points on the plane and each point is assigned a specific value, how can I retrieve the values interpolated to an arbitrary point in the colored figure below?
(Perhaps better understood by running the program below after the problem I posed.)
A practical concrete example of this is shown in the PATCH figure below. If I select 2 vertical lines and enter the coordinates of 5 points equally spaced on the lines, how can I retrieve the interpolated values at those purple points?
THE PROGRAM:
%Values of points
q = [0;2.00997512422418;2.11482859825566;0;...
1.50960259671213;1.00498756211209;1.47648230602334];
RGB = [0 0 1
0 0.5 1
0 1 1
0 1 0.5
0 1 0
0.5 1 0
1 1 0
1 0.5 0
1 0 0];
% data for patch (connectivity matrices)
msh_1.nn_tria = [3,2,7;2,6,7;5,3,7;6,5,7];
msh_1.nn_quad = [5,4,1,6];
msh_1.xy = [0,0;2,0;2,1;0,1;1,1;1,0;1.5,0.5];
%% Visualisation with patch
figure (8)
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_tria,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
patch('Faces',msh_1.nn_quad,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
FIGURE:
Do you have any idea how can I solve this problem?
Thank you so much for your helpful comments!
0 Comments
Accepted Answer
Voss
on 8 Mar 2024
Edited: Voss
on 8 Mar 2024
%Values of points
q = [0;2.00997512422418;2.11482859825566;0;...
1.50960259671213;1.00498756211209;1.47648230602334];
RGB = [0 0 1
0 0.5 1
0 1 1
0 1 0.5
0 1 0
0.5 1 0
1 1 0
1 0.5 0
1 0 0];
% data for patch (connectivity matrices)
msh_1.nn_tria = [3,2,7;2,6,7;5,3,7;6,5,7];
msh_1.nn_quad = [5,4,1,6];
msh_1.xy = [0,0;2,0;2,1;0,1;1,1;1,0;1.5,0.5];
%% Visualisation with patch
figure()
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_tria,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
patch('Faces',msh_1.nn_quad,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
% interpolate q at msh_1.xy to the required points
I = scatteredInterpolant(msh_1.xy,q);
[x,y] = meshgrid([0.68; 1.87],linspace(0,1,5));
v = I(x,y)
% visualization of interpolated values
str = compose('%.3f ',v);
text(x(:),y(:),str(:),'HorizontalAlignment','right','BackgroundColor','w')
line(x(:),y(:),'LineStyle','none','Marker','o','Color',[0.75 0 0.75],'MarkerFaceColor',[0.75 0 0.75])
% visualization of original (q) values, for comparison
figure()
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_tria,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
patch('Faces',msh_1.nn_quad,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
str = compose('%.3f ',q);
text(msh_1.xy(:,1),msh_1.xy(:,2),str(:),'HorizontalAlignment','right','BackgroundColor','w')
line(msh_1.xy(:,1),msh_1.xy(:,2),'LineStyle','none','Marker','x','Color','k')
4 Comments
See Also
Categories
Find more on Polygons 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!