On 20-Oct-2013 14:35, Nathan Hurst wrote:
There have been papers published on ways to do this efficiently in general (one search term is geometric interpolation). Nobody has implemented a competitive algorithm. I would recommend modifying the ellipse code to use the known approximation directly rather than going via sbasis (or equivalently, generating the approximation in sbasis form rather than using sin,cos in which case Geom::cubicbezierpath_from_sbasis should be the identity).
Recapitulating:
1. The original ellipse -> bezier conversion used one of the worked out solutions which are calculated directly from the ellipse parameters. Probably something like this:
http://www.spaceroots.org/documents/ellipse/
It produced four beziers for any ellipse. These met the needs of most users.
2. Higher precision curve drawing of ellipses was required by some end users for CAD purposes, so the method was changed. This resulted in the default bezier representation of an ellipse being more complex (>4 beziers) than needed for general use. The new method uses a fit parameter which must be changed in a major way from its default value in order to return to beziers similar to (1), and there is currently no way to do this in the GUI. (Unsure: that same parameter is used for other curve -> bezier conversions? Does the end user need to be able to adjust the fit parameter?)
So far so good?
The issue then is how to allow those who need it to obtain a higher precision conversion to beziers without requiring that the average user know anything about it. I suggest that the usual solution to this sort of problem, as applied to Inkscape, would be to modify the toolbar for elliptical drawing to add a "precision" field that normally reads "Default", with other options perhaps called "CAD Low","CAD Medium","CAD High". Each corresponds to a parameter value, but that is not shown to the end user, in case things need to be changed around again at some point in future. Exposing the parameter value is unlikely to be helpful to most users, since it probably will not correspond in a simple way to an easily comprehended measure of error. The bezier generating code looks at this parameter, and when it sees the one corresponding to "Default" it uses the original algorithm, for all of the others it uses Geom::cubicbezierpath_from_sbasis.
In terms of usability that should be fine, and adding the control will not be hard. However, algorithmically I am guessing that Geom::cubicbezierpath_from_sbasis is not as efficient as using some partially precalculated method which uses the a/b ratio of the ellipse in question, at least for whole ellipses. For circles in particular symmetry suggests that there must be an extremely efficient method of determining the best set of Beziers for a given measure of fit.
Regards,
David Mathog mathog@...1176... Manager, Sequence Analysis Facility, Biology Division, Caltech