Curve interpolation problem
2 views (last 30 days)
Show older comments
Hello, I have a project in the university to make a video of a car moving by a road defined by the user with the ginput() function. I can make this.. but the curve that the car is moving needs to be smoothed. So I tryed the 'basic fitting' tools and some more functions but the moving line is almost a closed curve... so I can`t make a smooth curve based on the poinst of the user input.
Can some one help me?! Here is an example of a user defined curve:
XX=[100.0000 167.3203 359.0253 410.6382 585.7535 716.6290 712.9424 476.9977 364.5553 185.7535 100.9608 86.2143];
YY=[150.0000 59.9470 107.8733 242.4355 100.5000 235.0622 441.5138 423.0806 529.9931 533.6797 364.0945 170.5461];
plot(XX,YY,'b-');
0 Comments
Accepted Answer
Teja Muppirala
on 8 Jun 2011
Maybe something like this?
XX=[100.0000 167.3203 359.0253 410.6382 585.7535 716.6290 712.9424 476.9977 364.5553 185.7535 100.9608 86.2143];
YY=[150.0000 59.9470 107.8733 242.4355 100.5000 235.0622 441.5138 423.0806 529.9931 533.6797 364.0945 170.5461];
plot(XX,YY,'b');
f = 10;
XXf = interpft(XX,numel(XX)*f);
YYf = interpft(YY,numel(YY)*f);
hold all;
plot(XXf(1:end-f+1),YYf(1:end-f+1),'r');
More Answers (4)
the cyclist
on 7 Jun 2011
The basic fitting tools are mostly designed to fit one function y=f(x) to all the data. But that is not what you are trying to do, so it is not surprise to me that those were not the right tools.
I think the hard part of this problem is hidden inside the simple phrase "needs to be smoothed". You will need to be much more explicit about what that means. Must the curve go through the points specified, or just near them? Must there be no kinks? Is it OK to have your curve go VERY far away from the points, in an effort to keep things smooth?
0 Comments
vasil enchev
on 7 Jun 2011
2 Comments
John D'Errico
on 7 Jun 2011
So then YES, you do need interpolation, and not smoothing. Interpolation is a process wherein the points themselves are not changed, but a smooth curve drawn between them. Smoothing allows the points themselves to be moved.
John D'Errico
on 7 Jun 2011
The interpolant can be a smooth one. It need not be a linear, connect the dots interpolant.
John D'Errico
on 8 Jun 2011
If you can't use a tool from the file exchange, but must write it yourself since this is a homework project, then you will need to do some writing.
A problem that you MAY find, is if you allow the interpolant to be a general smooth curve instead of piecewise linear segments, then you must constrain that curve to not pass through the walls of the coarse it appears to follow. Given that the splines ANY such tool must be based on are notorious for ringing, this may be an issue. Therefore, I would strongly recommend the 'pchip' method in interparc, as it is less susceptible to problems in this respect.
See Also
Categories
Find more on Vehicle Scenarios in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!