Creation of new waypoints between existing waypoints

5 visualizzazioni (ultimi 30 giorni)
Hi, I am working on a path following project. I managed to create a serie of waypoints WP=((x1,y2) (x2,y2) ... (xn,yn)) and results of path following are already satisfying. But I would to create new waypoints between existing waypoints for better results.
Note that coordinates can be positive or negative and x coordinates are not necessarily increasing.
This image is an example. Red points are existing waypoints and I begin to draw in blue new waypoints I would like to create.
Thanks for your helpCapture5.PNG

Risposte (3)

the cyclist
the cyclist il 25 Set 2019
You are not giving us very much info to go on here. But perhaps using the interp1 function to interpolate, possibly using a spline?
  1 Commento
Thomas LHOMME
Thomas LHOMME il 25 Set 2019
Thanks for answering quickly. Here is my list of waypoints. I would like to create new waypoints and to choose the spacing between them. I cannot use interp1 because for this function x must be strictly increasing. And I do not want to create a step of time to use spline. Is there other option ?

Accedi per commentare.


darova
darova il 25 Set 2019
Try this
% parameter - curve length
t = [0; cumsum(sqrt(diff(x).^2+diff(y).^2))];
% refine parameter
t1 = linspace(0,t(end));
xt = spline(t,x,t1);
yt = spline(t,y,t1);
plot(x,y,'o-r') % original data
hold on
plot(xt,yt) % interpolated data
hold off
  3 Commenti
the cyclist
the cyclist il 25 Set 2019
This solution worked nicely for me, but I had to change
t = [0; cumsum(sqrt(diff(x).^2+diff(y).^2))];
to
t = [0 cumsum(sqrt(diff(x).^2+diff(y).^2))];
because I used x and y as row vectors.

Accedi per commentare.


the cyclist
the cyclist il 25 Set 2019
Modificato: the cyclist il 25 Set 2019
In that case, you could do piecewise interpolation. If linear interpolation is fine, then this will work:
numOrigPts = numel(x);
numWayPts = 5;
xx = zeros(numWayPts*(numOrigPts-1),1);
yy = zeros(numWayPts*(numOrigPts-1),1);
for np = 1:numOrigPts-1
xint = (x(np+1)-x(np))/(numWayPts+1);
xx(numWayPts*(np-1)+1:numWayPts*np) = x(np) + xint*(1:numWayPts);
yint = (y(np+1)-y(np))/(numWayPts+1);
yy(numWayPts*(np-1)+1:numWayPts*np) = y(np) + yint*(1:numWayPts);
end
figure
hold on
plot(x,y,'*')
plot(xx,yy,'+')
where x and y are your original data. (Note that I have essentially recreated linear interpolation manually. I did this because you need to calculate the intervening x regardless, so doing the y values as well is exactly the same.)
But I think that @darova's solution is superior to this one, for making a smooth path around. See my comment there. However, mine has the advantage of creating equal numbers of waypoints between each original point, if that is important to you.

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!

Translated by