interpolation of coordinates in space using interp3
8 次查看(过去 30 天)
显示 更早的评论
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1498899/image.png)
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 个评论
Dyuman Joshi
2023-10-1
You need the equation/relation between the coordinates to interpolate, V contains the values of the the function corresponding to (X,Y,Z).
采纳的回答
Voss
2023-10-1
编辑:Voss
2023-10-1
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 个评论
更多回答(1 个)
Torsten
2023-10-1
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!