The problem with any single curve is that it can't convey discontinuous curvatures, such as flat objects with distinct corners, and you need multiple curves for that, resulting in a spline. For all the examples posted here, you can always reduce this to a list of cubic equations, to be selected based on the input coordinate. (e.g. 0-0.8 uses equation a, 0.8-0.9 uses equation b to go around the corner, and 0.9-1.0 uses equation c for the side of the screen)
If you then use a traditional B-spline or a catmullrom for the actual drawing, that is just choosing a method of inputting that data with visual aids. In the end, what you probably want is some code that finds a through d in fn = ax³+bx²+cx+d where fn(0) = starting point, fn(1) = end point, fn'(0) = starting direction and fn'(1) = ending direction. It's on the easy end of the spectrum for those mathematically inclined, but it's also often good enough to scare people away.
And even though catmullrom and all the other cardinal splines have the property of each control point actually being touched, they are a liability for various other things. For instance, to make a single corner in the screen, you will want a polygon piece that's exactly horizontally oriented on one side, and exactly vertically oriented on the other side. That means that the control point immediately before and after of the starting point must be horizontal respective to each other, and that the control points immediately before and after the end point are vertical in respect to each other. That leads to a paradoxal situation (taking your middle photo as an example):
Code: Select all
^ A must be on this line to avoid bulges :(
·
A**/ /*****B** ······> C must be on this line to avoid bulges :(
*
*
C
*
*
D
In addition, all the stock B-splines fail if you also want to be able to map actual pixel coordinates correctly, because the plotting coordinate will give the same amount of pixels in A-B as there are in B-C and C-D, or basically, there would mathematically be more pixels in the little screen corner than there is on the primary screen.
Both problems can be fixed by actually specifying the "time" coordinate per spline point, as well as the actual mapping angle. Of course, you can still use the cardinal/catmull-rom equations to suggest initial angles for you and it's probably good to get away with in a fair few cases. You can segment the actual screen in colours to live aid in selecting the actual pixel coordinates, but by now your base mathematical model has already become a
non-uniform B-spline
There's one problem left: up to now there have only been polynomial splines, and they can't do circles or ellipses, and you will get to see them in practice: B-C above probably is a quarter circle rather than a parabola. To fix that, you need
NURBS, and I can imagine a significant bigger portion of programmers running away at this moment.
Brendan wrote:I looked at Catmull-Rom splines, and couldn't figure out how to handle the first and last points correctly.
One of the most common conventions is that the "missing" neighbours of the start and end points are at the same location as the start and end points themselves. And as you have shown, there are sufficient other options and in the end you might just want to deal with it like the problem sketch above.