Scaling a spline in MATLAB
5 次查看(过去 30 天)
显示 更早的评论
Hello I have a spline that I've created using pchip. Now I want two other splines, one scaled down version of the original and one scaled up version. Think of it like a Nascar track, I have the center line but I also want the inner and outer track lines (splines). I've tried by transforming the points on the original line along its normal but they then overlap on the inside in corners. Is there a way to properly scale a spline in Matlab?
Best regards MC
0 个评论
回答(1 个)
John D'Errico
2017-6-15
A racetrack would imply a constant bias on either side, thus a uniform distance normal to the curve. While that is quite computable, the result would not be easily representable as a spline.
If you want a simple constant vertical shift, thus a constant offset up and down, then just do three spline fits.
pp.base = pchip(x,y);
pp.upper = pchip(x,y + delta);
pp.lower = pchip(x,y - delta);
In fact, there are even simpler ways to accomplish a constant offset, by working with the spline coefficients themselves, taken from the pp form of the spline. But the above is simple and easy to work with. Since pchip is fast, unless this was a computational bottleneck, the alternative is probably not worth showing you.
Again, the constant vertical shift will NOT produce a pair of curves at a uniform normal distance above and below the curve. That is something a bit more difficult to achieve.
I have no idea what you want by "scaling" a spline. Yes, there are certainly things you could do. If you want to do some sort of proportional scaling, then you need to say what you want, if the above is not adequate.
2 个评论
John D'Errico
2017-6-16
This is not a scaling of a spline, not in any way. Nor is it a simple additive translation, since it is easy to create a curve that completely lacks a point of the desired uniform normal distance in some regions of the curve.
For example, suppose I create a curve as a circular arc of radius 1. The curve is a perfect circle. Now, you might choose to create a new curve that is offset by 1.5 units, on either side of the curve.
On the outside of your circles, this will result in a new circle that has a radius of 2.5, so a uniform distance of 1.5 units outside the circle.
But inside the curve, there exists NO point, NO curve that is a uniform distance of 1.5 units inside a circle of radius 1.
The point is, it is quite easy to create a problem that completely lacks a solution as you want to see it. As well, you can create a more complicated (non-circular) problem that will cause your scheme to fail in arbitrary locations.
Worse, I can draw a simple non-convex curve which would have a curve offset as you would want it that is not even composed of contiguous segments.
While the above issues are resolvable with some difficulty, the resolution would not be at all trivial. If your goal in this is just to program a game, IMHO I doubt it is worth the effort.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!