1) Generate intermediate points in a set of X,Y while respecting the original points order. 2) Generate same number of points for 2 different set of X,Y with different sizes.

65 Ansichten (letzte 30 Tage)
1) Generate intermediate points in a set of X,Y in matlab while respecting the original points order.
2) Generate same number of points for 2 different set of X,Y with different sizes.
I hope my question is clear.
Imagine I have 2 variables with totaly different sizes :
a=[2,1;2,2;1,4;-1,4;-2,1;-2,-2;0,-3;1.5,0];
b = [3,2;3,3;2,5;0,6;-2,5;-3,2;-3,-1;0,-4;2,-2];
I need to generate 2 variables of same dimensions (say 1000 points, Equidistant) from a and b. the first strating with a-start and the second with b-start.
3) I have something like this in 3D but hope an idea to do it for 2D will work also for 3D
Thank you
  3 Kommentare
Mohamad TOUT
Mohamad TOUT am 16 Okt. 2025 um 10:15
Hi,
I want a kind of interpolation of each curve separately.
The idea of resampling both curve should be based on same number of points and the starting points of each original curve.
Mathieu NOE
Mathieu NOE am 20 Okt. 2025 um 10:02
As always , my pleasure !
and we should also warmly thanks @John D'Errico for his marvelous Fex submissions

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 16 Okt. 2025 um 14:24
my turn to try something... with the help of interparc :
NB that nothing forces the two curves to be parallel (otherwise it would be better to start with a central line and then create the two "borders")
try with the different interpolation methods and pick the one you prefer
here also I took only N = 100 points so we can clearly see them on the plot, but you can opt for more if you want..
may I also point out that going from a very low sampling like 8 points to 1000 interpolated points leaves a lot or room to "interpret" what shape you want to follow (linear, polynomial - which order ?)
a=[2,1;2,2;1,4;-1,4;-2,1;-2,-2;0,-3;1.5,0];
b = [3,2;3,3;2,5;0,6;-2,5;-3,2;-3,-1;0,-4;2,-2];
plot(a(:,1),a(:,2),'ro','markersize',20);grid
hold on
plot(b(:,1),b(:,2),'gs','markersize',20),grid
% interpolate using parametric splines
N = 100;
pta = interparc(N,a(:,1),a(:,2),'pchip');
ptb = interparc(N,b(:,1),b(:,2),'pchip');
% Plot the result
plot(pta(:,1),pta(:,2),'r-*');
plot(ptb(:,1),ptb(:,2),'g-*');
hold off
grid on
axis equal
  2 Kommentare
John D'Errico
John D'Errico am 16 Okt. 2025 um 15:01
If the goal is equidistant points along an arc, interparc is the right tool. And it works in any number of dimensions. Of course, I may be biased. ;-)
Mohamad TOUT
Mohamad TOUT am 19 Okt. 2025 um 8:26
Thank you so much, Mathieu.
Thanks to all of you. This is exactly what I was looking for.
The results in my case study are truly surprising!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Alan Stevens
Alan Stevens am 16 Okt. 2025 um 12:46
Bearbeitet: Alan Stevens am 16 Okt. 2025 um 12:48
Something like this? (I've just used 50 interpolated points for clarity below). Choose your own interpolation type. The "equidistant" below is interpreted as equal angle separation.
a=[2,1;2,2;1,4;-1,4;-2,1;-2,-2;0,-3;1.5,0];
b = [3,2;3,3;2,5;0,6;-2,5;-3,2;-3,-1;0,-4;2,-2];
plot(a(:,1),a(:,2),'ro-',b(:,1),b(:,2),'bs-'),grid
hold on
% convert to polar coordinates
[tha,ra] = cart2pol(a(:,1),a(:,2));
[thb,rb] = cart2pol(b(:,1),b(:,2));
tha(tha<=0)=tha(tha<=0)+2*pi;
thb(thb<=0)=thb(thb<=0)+2*pi;
na = length(tha);
nb = length(thb);
n = 50; % Nbr of interpolated points
i = 1:n;
thetaa(i) = (tha(na)-tha(1))*(i-1)/(n-1) + tha(1);
thetab(i) = (thb(nb)-thb(1))*(i-1)/(n-1) + thb(1);
xa = interp1(tha,a(:,1),thetaa);
ya = interp1(tha,a(:,2),thetaa);
xb = interp1(thb,b(:,1),thetab);
yb = interp1(thb,b(:,2),thetab);
plot(xa,ya,'*:',xb,yb,'+:')
  2 Kommentare
Mathieu NOE
Mathieu NOE am 16 Okt. 2025 um 13:21
I wonder if the OP wanted something like a spline interpolation, and with equidistant with ds = sqrt(dx²+dy²) in mind ?
Mohamad TOUT
Mohamad TOUT am 16 Okt. 2025 um 13:28
Thanks for this idea.
but unfortunately this will no work for me. Maybe I gave a wrong data set as example.
Just try to add one point (outside the circle) at the end of b for example : 4,4. Then the interp1 will not work anymore.
//// Please imagine this problem like a F1 track with both set of points are the left and right side of the track :) \\\\

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by