[cairo] Path length
Stuart Axon
stuaxo2 at yahoo.com
Wed Mar 25 02:32:22 PDT 2015
Ah, that turns out to be quite understandable, it's a long time since I did any C, but will give it a go.
S++
On Wednesday, March 25, 2015 2:27 AM, Krzysztof Kosiński <tweenk.pl at gmail.com> wrote:
2015-03-24 20:16 GMT+01:00 Behdad Esfahbod <behdad.esfahbod at gmail.com>:
> On 15-03-24 01:45 PM, Bryce Harrington wrote:
>> On Tue, Mar 24, 2015 at 05:09:50PM +0000, Stuart Axon wrote:
>>> Is the best way to get the length of a cairo path to call cairo_copy_path_flat and sum the lengths of the LINE_TOs contained inside ?
>
> That's what I've personally done in the past. However:
>
>>> I've been looking at arc lengths and it seems it can get complex,
>
> There are very decent and simple approximations that I think are good enough
> for most purposes. Read here for example:
>
> http://pomax.github.io/bezierinfo/#arclength
>
> Would be interesting to measure or calculate the error of that approximation
> for small values of n.
Numeric integration from the definition of arc length is an absurdly
complicated solution for the case of Beziers.
Instead, you can exploit the trivial geometric fact that a Bezier
curve is longer than the polyline joining its control points, but
shorter than the distance between its endpoints. If the difference
between those is higher that the precision, do recursive Casteljau
subdivision and repeat on the parts.
Here is a simple implementation with comments:
http://bazaar.launchpad.net/~lib2geom-hackers/lib2geom/trunk/view/head:/src/2geom/bezier-curve.cpp#L274
Regards, Krzysztof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20150325/832ce357/attachment.html>
More information about the cairo
mailing list