Hi,
Combuster wrote: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
I'd hope that, given a set of control points like "(-10,0), (-2, 0), (0, -2), (0, -5)", a correct curve fitting algorithm would give a perfectly horizontal line for "(-10,0) to (-2, 0)", a perfectly round curve with a radius of 2 for "(-2, 0) to (0, -2)" then a perfectly vertical line for "(0, -2), (0, -5)". I'm starting to think that none of the methods of dealing with splines fit my definition of "correct".
Further; I'm wondering if it makes sense to store a "surface normal" for each control point. That way my curve fitting algorithm only needs to care about 2 points (or, for points N and N+1 it doesn't need to care about point N-1 or point N+2). That would also make the curve fitting something that's easily understood (by me):
Essentially; I'd be able to have 2 actual control points (P0 and P2 in that diagram) and use the control point's surface normals to find the point of intersection (P1 in that diagram), then generate the curve (which looks like it only involves doing "find the point i% of the way along the line" three times, where i ranges from 0% to 100%).
Combuster wrote: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
If I split the screen into an arbitrary number of rectangles ("X columns and Y rows") where all columns have a fixed width and all rows have a fixed height; it ends up being a little bit like using sample points to describe a sound wave - by increasing the number of control points you increase the accuracy of the final curve (e.g. that smartphone in the second picture you might have 60 control points on the same straight line followed by 4 that aren't). In this case it's easy to map pixel co-ords correctly because there are the same amount of pixels in A-B as there are in B-C (at least, if you ignore rounding errors - e.g. where you've got 123.5 pixels in A-B and B-C).
However; now I'm thinking you're right; in that it'd make much more sense to split the screen into an arbitrary number of rectangles ("X columns and Y rows") where the columns and rows have arbitrary width/height. This would save space by avoiding pointless control points (e.g. that smartphone in the second picture could be 4 control points instead of "lots of them").
Combuster wrote: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.
For a quarter circle; that quadratic bezier curve (the animated diagram above that I mentioned because it's easy for me to understand) would give a parabola. However, with just 3 control points instead of 2 it'd probably approximate a quarter circle with only a small/unnoticeable amount of error (and with more control points the error would be reduced further); and I'm thinking this is probably good enough (especially compared to the error you get from most OSs that assume the screen is flat).
For something that's a lot more complicated (e.g. NURBS); the error might be zero in theory, but you can bet someone (me) will screw it up and the error will be significantly higher in practice.
Note: In theory (assuming 2D for simplicity); a pair of "points with normals" is enough to uniquely describe an ellipse, which means that it's enough to give perfectly round curves (including "quarter circle"). I'm currently researching this (looking for formulas for an ellipse that only uses "points with normals" or "points with tangents" as parameters and not finding one). However, I suspect that this approach will require things like sine, cosine and/or square root (unlike that quadratic bezier curve which doesn't) and will be something I'd prefer to avoid for the sake of performance and/or precision loss.
Combuster wrote: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.
Originally I assumed that (for Catmull-Rom splines) if the "missing" neighbours of the start and end points are at the same location as the start and end points themselves, then you'd end up with a division by zero or some other "not a number" insanity. I did some research today and I think you're right (in that Catmull-Rom can handle duplicate points if implemented properly).
However; I'm also starting to realise there isn't one correct solution. For example, given 3 points and no other information, there's an infinite number of curves that could all be considered correct, and there is no method (that can be implemented in software) to determine which "correct" set of curves are the curves that were actually intended. Based on this I think more information is required - either adding a lot more control points and/or adding "surface normals" (or tangents, or whatever), and/or adding a way to specify the method to use for generating each individual curve.
Cheers,
Brendan