Skip navigation.
 
mlRe: How to import drawing paths into a Cocoa application?
FROM : Graham Cox
DATE : Sun Apr 27 06:23:32 2008

On 27 Apr 2008, at 12:24 pm, John C. Randolph wrote:
>
> On Apr 21, 2008, at 5:35 PM, Graham Cox wrote:

>>
>> - (NSPoint)    pointOnPathAtLength:(float) length slope:(float*) slope;

>
> I notice that your lengthOfBezier() function does an approximation 
> similar to what we'd get in postscript by executing flattenpath and 
> then adding up the lengths of the resulting line segments.


I generally find that Quartz doesn't flatten by that much in practice 
(though of course you can set this value), so the spacing is quite 
coarse between each point especially for already quite "flat" curves, 
making it not that suitable for calculating the length - you still end 
up having to interpolate the last segment.

In my code it actually does a binary subdivision of each curve segment 
until the point on the path is within some epsilon of the wanted point 
- I typically use 0.1 (points) as certainly on screen this is very 
adequate and takes very little time to execute to this degree of 
accuracy. Even for printed output that's only one pixel error at 
720dpi, so it's pretty close. Most of the time you're interested in 
something that looks right, so a mathematically perfect solution is 
not really warranted.

> I've asked several math majors over the years if they could give me 
> an exact function for the length of a bezier curve.  They've 
> generally told me it was possible, but none of them actually 
> produced it.


Yup, that seems similar to my experience too, all talk and no trousers!

G.

Related mailsAuthorDate
mlHow to import drawing paths into a Cocoa application? Steve Weller Apr 22, 02:23
mlRe: How to import drawing paths into a Cocoa application? Graham Cox Apr 22, 02:35
mlRe: How to import drawing paths into a Cocoa application? Graham Cox Apr 22, 02:46
mlRe: How to import drawing paths into a Cocoa application? Steve Weller Apr 27, 00:43
mlRe: How to import drawing paths into a Cocoa application? John C. Randolph Apr 27, 04:24
mlRe: How to import drawing paths into a Cocoa application? Graham Cox Apr 27, 06:23
mlRe: How to import drawing paths into a Cocoa application? Jens Alfke Apr 27, 06:44