Creation of new waypoints between existing waypoints
조회 수: 4 (최근 30일)
이전 댓글 표시
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 help

댓글 수: 0
답변 (3개)
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?
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
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
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!