Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resample or interpolate a unevenly spaced path

Let's say I have a path made of 3D points, where the distance between consecutive points is not constant.

How do I resample it such that distance between consecutive points becomes constant?

I tried to look into interp1 but I don't know original query points of a hypotetically parametrized curve x(t),y(t),z(t).

Example path:

enter image description here

like image 779
fferri Avatar asked Jul 14 '15 10:07

fferri


1 Answers

You can use interparc from the Matlab File Exchange. In the following example, this function calculates 100 equally spaced points of the original curve. By default a spline-interpolation is used and gives a smooth curve. By defining an optional parameter, we can change this behaviour. Use 'linear' for a linear approximation (most efficient).

Here is the code:

% define some original points
A = [0.132488479262673 0.427113702623907;0.160138248847926 0.462099125364431;0.197004608294931 0.532069970845481;0.236175115207373 0.634110787172012;0.263824884792627 0.677842565597668;0.284562211981567 0.709912536443149;0.307603686635945 0.744897959183673;0.339861751152074 0.785714285714286;0.376728110599078 0.806122448979592;0.40668202764977 0.814868804664723;0.452764976958525 0.817784256559767;0.498847926267281 0.82069970845481;0.521889400921659 0.82069970845481;0.542626728110599 0.82069970845481;0.561059907834101 0.817784256559767;0.579493087557604 0.806122448979592;0.639400921658986 0.759475218658892;0.669354838709677 0.721574344023324;0.713133640552995 0.654518950437318;0.752304147465438 0.581632653061224;0.784562211981567 0.485422740524781;0.793778801843318 0.412536443148688;0.784562211981567 0.316326530612245;0.773041474654378 0.284256559766764;0.754608294930876 0.260932944606414;0.722350230414747 0.231778425655977;0.660138248847926 0.214285714285714;0.567972350230415 0.188046647230321];

% plot original
figure
plot(A(:,1),A(:,2),'*-')

% interpolate
B = interparc(100,A(:,1),A(:,2));             % spline
%B = interparc(100,A(:,1),A(:,2),'linear');   % linear

% plot interpolated
figure
plot(B(:,1),B(:,2),'*-')

This is the result: result1_1result1_2

like image 175
Matt Avatar answered Sep 20 '22 02:09

Matt