Scaling a spline in MATLAB

5 views (last 30 days)
MC
MC on 15 Jun 2017
Commented: John D'Errico on 16 Jun 2017
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

Answers (1)

John D'Errico
John D'Errico on 15 Jun 2017
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 Comments
MC
MC on 16 Jun 2017
Edited: MC on 16 Jun 2017
Thank you for your answer!
What I'm trying to achieve is a uniform normal distance from the base spline to the outer and inner curve. It doesn't actually have to represented as a spline, any visual representation is good enough. I have attached an image of my failed attempt, where I translated the points on the base line along the normal of the respective points on the baseline. The blue circles are the break points of the center spline. One can see the overlapping that occurs
The center spline might have to be changed in order to be able to generate proper inner and outer lines? That's okey to change it I'm sorry if I'm not used the correct terminology, I'm not too familiar with splines. I just remember when I used to work with Catia and how one could easily draw a spline and the scale it however one saw fit.
John D'Errico
John D'Errico on 16 Jun 2017
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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!