Interpolation to arbitrary points on a patch plot

4 views (last 30 days)
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!

Accepted Answer

Voss
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)
v = 5×2
0.6834 1.8793 0.6834 1.8838 0.7742 1.9101 0.9004 1.9363 1.0265 2.0361
% 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

Sign in to comment.

More Answers (1)

Matt J
Matt J on 8 Mar 2024
Edited: Matt J on 8 Mar 2024
For example,
F=scatteredInterpolant(msh_1.xy, q);
interpolatedValues = F({[0.68,1.87],0:0.2:1})

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!