4 ms·
I'll say a little more, as you've obviously put some time into trying to understand the code. You're generally on the right track. The curve family is basicall
by raphlinus 6y ago
I'll say a little more, as you've obviously put some time into trying to understand the code. You're generally on the right track.
The curve family is basically the same as the 4-parameter spline curve in my thesis when bias <= 1.0, except the parametrization is different. The magic (the "seemingly bizarre function") happens when bias > 1.0, in which case it describes a curve that's inspired by an elastica as the tension goes up, though the details are a bit different. Also note that when both bias values are 1.0, the curve is an Euler spiral, which I consider especially beautiful and suitable for interactive design.
Regarding solving the curve equations, yes, it has to do some solving in order to get the curve into place. It doesn't have to be a full differential equation solver, though, fundamentally it's a doubly nested integral - the expression of curvature as a function of arclength is a Cesàro equation, and integrating that once gives a Whewell equation.
G2 continuity is enforced by the spline solver, particularly `iterate` (with some help from `adjust_tensions` for cases where an auto point is opposite on off-curve point). The current version of that solver is a bit hacky and not 100% robust. Basically it computes the curvature error at each on-curve point, then pushes the tangent at that point in the direction of reducing the error.
As I said, I'll do a full explanation of the math before long. Hopefully that will address a lot of your questions.
- AnthonBerg 6y agoI just want to say how deep my appreciation of your work is. I've skimmed your thesis in preparation for reading it closely and I've seen enough to recognize it as beautiful. This recent work too. I started thinking about bezier curves in the ... '80s? '90s? – as a child I was basically raised at my grandmother's graphic design office in front of Macintosh computers. I had the Adobe Illustrator pen tool in my hands as a child and later, FreeHand's bezigon tool. The hyperbezier pen tool is beautifully natural to use ("This is it!") – I'm also very glad that I've almost by chance learned enough mathematics to grasp how it works and how it was arrived at. Just barely. And I'm glad that I'm going to learn more math and understand it more completely.
- raphlinus 6y agoYour comments warm my heart greatly. Thanks, and I hope you continue enjoying your learning path.
- dan-robertson 6y agoSo I looked into this a bit more. I think the optimisations in the calculations threw me off a bit, but I understand now: - to draw a curve, it has some starting angle and you move a small amount in that direction and then adjust the angle. The rate the angle changes is the signed curvature. - therefore the angle change over the whole curve is the integral of the curvature between 0 and 1. (This simplifies the differential equations into dX/ds = (cos theta, sin theta), dtheta/ds = k.) - because we don’t care about the initial angle, there’s a trick in the way an integral is computed to simplify the code (\int_{1-s}^1 f(s) ds = \int_0^1 f(s) ds - \int_0^{1-s} f(s) ds, but the first term is a constant so can be folded into the starting angle). - the k0,k1,bias0,bias1 parameters give curves but they don’t much correspond to the things you care about (initial and final angle relative to the chord and chord length relative to arc length), so to go from the parameters you want to the curve, you do an optimisation step to find a curve for your desired parameters. This feels a bit expensive (you need to effectively solve the differential equation above to find the chord length. Maybe there’s an analytic solution (surely there is when f is polynomial) but there’s 8-18 cases and the integrals look gnarly) - there’s an error in the definition of the basis function in the bias<1 case, it should be doubled. I guess a thing I still don’t understand is what motivates the particular choice of the basis function. There doesn’t seem to be anything very natural about either of the cases. I was also thrown off by the definition of k because I expected it to be roughly like interpolation (I.e. f(b,-) would always be strictly increasing with f(b,0)=0,f(b,1)=1), but f(b,1) can range over a pretty wild set of values.)