Interpolating trajectory from unsorted array of 2D points where order matters

一世执手 提交于 2019-12-01 12:24:27

It sounds like you need to be using interp1 in a loop (i.e. to preserve original order) interpolating between each consecutive pair of points:

X = [10; 10.0001; 9; 48];   %// You can consider something like X = [10;10;9;48]; X=X+rand(size(X))*0.0001 instead of dealing with equal X values manually
Y = [10; 20; 50; 6];

m = 3333; %//num points between nodes
n = m*(length(X)-1);

Yi = zeros(n,1);
Xi = [];
for k = 1:length(X)-1
    xi = linspace(X(k), X(k+1), m);
    Xi = [Xi, xi];
    Yi(((k-1)*m+1):k*m) = interp1(X(k:k+1), Y(k:k+1),xi); 
end

plot(X,Y,'or');
hold on
plot(Xi,Yi);

To get a pentagon (not a W) try this looping code with these inputs:

X = [0.25; 0.75; 1; 0.5; 0; 0.25];
Y = [0; 0; 1; 1.8; 1; 0];

Result:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!