interpolation of coordinates in space using interp3
8 views (last 30 days)
Show older comments
Hi! I have this coordinate set (C_new). I would like to add additional coordinates using interpolation.
load C_new
figure
plot3(P(:,1),P(:,2),P(:,3),'k*','Markersize',20);
hold on
plot3(C_new(:,1),C_new(:,2),C_new(:,3),'r.','Markersize',10);
hold off
axis equal
I'm proceeding as follows but I don't know if it's the right procedure:
X = C_new(:,1);
Y = C_new(:,2);
Z = C_new(:,3);
[Xq,Yq,Zq] = meshgrid(X,Y,Z);
Vq = interp3(X,Y,Z,V,Xq,Yq,Zq);
but what should I put for V?
1 Comment
Dyuman Joshi
on 1 Oct 2023
You need the equation/relation between the coordinates to interpolate, V contains the values of the the function corresponding to (X,Y,Z).
Accepted Answer
Voss
on 1 Oct 2023
Edited: Voss
on 1 Oct 2023
interp3 is for interpolating a function of 3 variables, i.e., if you had a function f(X,Y,Z) that returns a value for each (X,Y,Z) then you could use interp3 to interpolate those values to new points in 3D space. In this case there is no function, only the points in 3D space, so you can define a parameterizing variable and use interp1 to interpolate each of your X, Y, Z in terms of that
load C_new
% original number of points:
n = size(C_new,1);
% number of points you want (change this as desired):
n_new = floor(n/2);
% distance between adjacent points:
d = sqrt(sum(diff(C_new,1,1).^2,2));
% cumulative distance around the ring, starting with point #1:
t = [0; cumsum(d)];
% new distances (equally-spaced) at which to calculate the new (X,Y,Z) coordinates:
t_new = linspace(t(1),t(end),n_new);
% interp1 C_new from t to t_new:
C_interp = interp1(t,C_new,t_new);
% plot:
figure
plot3(C_interp(:,1),C_interp(:,2),C_interp(:,3),'g.','Markersize',6);
hold on
plot3(C_new(:,1),C_new(:,2),C_new(:,3),'r.','Markersize',10);
axis equal
0 Comments
More Answers (1)
Torsten
on 1 Oct 2023
Given two points
P1 = [1 3 4];
and
P2 = [3 6 -1];
you can connect them by a line
s = @(t) (1-t)*P1 + t*P2;
and choose points between them:
t = [0:0.2:1];
Pq = reshape(cell2mat(arrayfun(@(t)s(t),t,'UniformOutput',0)),3,[]).'
0 Comments
See Also
Categories
Find more on Interpolation 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!