Re: Path length

Krzysztof Kosiński <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAFLw2WTGSKa637D-H=q78867pXu66RcFaxgcH=-XeyD1jQDcKw@mail.gmail.com>
2015-03-24 20:16 GMT+01:00 Behdad Esfahbod <[email protected]>:
> 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
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.