Remeshing points on curved line
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have the arclength coordinates S1, S2, S3 ... SN of N = 551 points along a curved line.
I would like to now "squeeze" in 6,001 points (without increasing the total length) and determine the new arclength coordinates S1, S2, S3 ... SM (M = 6,001).
I don't want to consider the obvious solution of dividing up the total length evenly unless I have to. Rather, I ideally want to keep as many of the original points fixed as possible.
Thank you!
3 Commenti
Risposta accettata
Matt Tearle
il 20 Mar 2013
If I understand the problem correctly, you have an array of m monotonically increasing, but unequally spaced, values. You want an array of n (> m) values than include the original m data points, but fill in the gaps between them.
I don't see a particularly nice solution -- even interpolation is tricky because you still want to keep the unequally spaced points.
Here's one possibility: take the m data points as m of the n points in your result, and distribute the remaining n - m points equally between the m - 1 spaces between the m data points. Given that you want to maintain the same density, equal distribution would do that fairly well. In that case, you need about k = (n-m)/(m-1) points between each pair of data points. Of course, that probably won't be an integer, so one solution would be to round that value down, leaving you with between 0 and m-1 leftover points to distribute. Here's my solution, distributing them to the biggest spaces between the data points:
%%Make some data
m = 31; % number of data points
n = 82; % number of points to interpolate onto
x = sort(rand(m,1));
%%Figure out the number of points between each data point
% Start with even distribution, rounded down
numbetween = floor((n-m)/(m-1));
% Make a vector to use with linspace (add 2 to include the endpoints)
k = 2 + numbetween*ones(m-1,1);
% Distribute the leftovers to the largest spaces
dx = diff(x);
[~,idx] = sort(dx,'descend');
numleftover = n - m - (m-1)*numbetween;
% Add one to the largest NUMLEFTOVER spaces
k(idx(1:numleftover)) = k(idx(1:numleftover)) + 1;
%%Make interpolated data
y = zeros(n,1);
% Loop over the m-1 spaces between the data points
i1 = 1;
for j = 1:(m-1)
% Add k points between x(j) and x(j+1)
i2 = i1 + k(j) - 1;
% Remember that k had 2 added to it, to account for the endpoints when
% using linspace
y(i1:i2) = linspace(x(j),x(j+1),k(j));
i1 = i2;
% Note that y(i2) will be overwritten next time through the loop, but
% it will get the same value (x(j+1)) anyway
end
%%Visualize the results
plot(x,0*x,'o',y,0.1+0*y,'x')
axis([0,1,-1,1])
(I'm using x for what you called S, and I just realized I have m and n reversed from what you had, sorry!)
0 Commenti
Più risposte (1)
Wouter
il 20 Mar 2013
Modificato: Wouter
il 20 Mar 2013
If it is a straight line with evenly spaced points you could do this:
S % original S; % Nx2 matrix
from_value = S(1); % first point, assuming S is sorted
to_value = S(end); % last point
new_S = [linspace(from_value,to_value,length(S)+6001)]; % new S is 6001 points larger
However if the S is a curve, it is a bit more difficult; you would need to fit a polygon or a spline which decribes your current curve and then resample it using 6001 more points.
2 Commenti
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!