[cairo] Ellipse stroke
rcopley at gmail.com
Tue Nov 14 20:01:46 UTC 2017
I don't think the result of adding an elliptical arc to a path and
stroking the path is right, if the ellipse's minor semiaxis is small
compared to the line width.
I put a little program at https://buster.me.uk/cgit/cairo-bug.git
to illustrate. The output PNGs are there too (use the "plain" links).
The top part of each image is what current Cairo paints when stroking
an elliptical arc, from 0 to pi radians, with a large line width.
In my opinion, image 0 is perfect, images 1 and 2 are incorrect,
and there's a different issue (possibly a Cairo bug?) that affects
images 3 to 11 more and more severely.
I can see the advantages of the current method, that it mostly works
fine and is straightforward to describe and implement.
I have a suggestion for a possible solution too, though the
mathematics of it is beyond me for the moment.
You see, as the minor axis of the ellipse tends to zero, the path
tends to a 'limit path' which is a straight line of length the major
axis, preceded and followed by infinitesimal segments perpedicular to
And, I propose, that limit path should be stroked as if it is simply a
straight line. (As if the infinitesimal sections don't exist at all).
And as the minor radius changes continuously from "OK" (as in image 0)
through "not OK" (as in images 1 and 2) tending towards zero, the
stroked region should change continuously from the "OK" ellipse stroke
in image 0 to the "limit path" straight line.
That's all just explaining what I'd like to accomplish, not how I
would do it.
How I would do it is: find the points where the current Cairo stroker
would make a cusp (as in image 2), if any. Truncate the path being
stroked at the cusp(s). Extend the stroke with a circular segment
centre the cusp, in such a way that the leading edge of the stroked
region exactly reaches the endpoint of the path.
Clear as mud?
It's a fun problem, You'll love it. Linear algebra, calculus /and/
trigonometry. A real treat.
More information about the cairo