Creation of new waypoints between existing waypoints

조회 수: 4 (최근 30일)
Thomas LHOMME
Thomas LHOMME 2019년 9월 25일
편집: the cyclist 2019년 9월 25일
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

답변 (3개)

the cyclist
the cyclist 2019년 9월 25일
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
Thomas LHOMME
Thomas LHOMME 2019년 9월 25일
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 ?

댓글을 달려면 로그인하십시오.


darova
darova 2019년 9월 25일
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
darova
darova 2019년 9월 25일
Too sad. Maybe another time?
the cyclist
the cyclist 2019년 9월 25일
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.

댓글을 달려면 로그인하십시오.


the cyclist
the cyclist 2019년 9월 25일
편집: the cyclist 2019년 9월 25일
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.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by