[cairo] Path length
tweenk.pl at gmail.com
Tue Mar 24 12:27:37 PDT 2015
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:
> 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:
More information about the cairo