Re: How to import drawing paths into a Cocoa application?
On Apr 21, 2008, at 5:23 PM, Steve Weller wrote: I my app I want to be able to use drawing paths for two purposes: 1. Clip images to the path 2. Generate points that lie on the path as a function of the distance along the path I want to be able to create paths with Omnigraffle or some other vector-image app, and export them to PDF or EPS or equivalent format. The objects I am dealing with could have multiple path segments and/or paths that intersect themselves and each other. I will probably use Quartz rather than Cocoa drawing. I expected to see a class method for NSBezierPath that would grab a path from a file, but it is not there. So: 1. What file format should I use to store my paths? 2. How do I get the path into an object that I can use? I can clip images to a path by using the addClip method on the NSBezierPath. Are there any easy ways of calculating the points on the path as a function of the distance from the start of the path? Having researched #2 above and found a number of resources that say It's not trivial, I encountered the developer example code for Voyeur. It's an app that looks inside PDFs and extracts, lists, and renders them. So there is a decent example, but it is certainly not trivial. Carbon and Quartz. I pretty much expected to be working in Quartz, but it looks like there are no nice Cocoa classes to help me. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: How to import drawing paths into a Cocoa application?
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'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. If there are any mathematicians on this list who can solve for the length of a bezier cubic spline, please enlighten me! -jcr ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: How to import drawing paths into a Cocoa application?
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. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: How to import drawing paths into a Cocoa application?
On 26 Apr '08, at 7:24 PM, John C. Randolph wrote: 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. A math major's notion of an exact function probably allows integral signs. :-P I looked into similar operations on cubic curves (though not specifically path length) years and years ago when I worked on a font- design program. There are a few easy operations, like getting the bounding-box, but otherwise the math tends to get really hairy. In the case of length, you're solving a path integral, and if I remember my college calculus*, the integrand will be a tangle of roots of sums of sixth powers. Everything I've read since indicates that the universal solution is to flatten the curves and do the rest of the work on polygons, which is far easier. (One of the exceptions was Apple's old QuickDraw GX: like TrueType fonts, it was based on quadric curves, which are less flexible but mathematically more tractable. GX apparently had code for doing a lot of operations directly on curves without having to flatten them first.) —Jens * I don't. o_O smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
How to import drawing paths into a Cocoa application?
I my app I want to be able to use drawing paths for two purposes: 1. Clip images to the path 2. Generate points that lie on the path as a function of the distance along the path I want to be able to create paths with Omnigraffle or some other vector-image app, and export them to PDF or EPS or equivalent format. The objects I am dealing with could have multiple path segments and/or paths that intersect themselves and each other. I will probably use Quartz rather than Cocoa drawing. I expected to see a class method for NSBezierPath that would grab a path from a file, but it is not there. So: 1. What file format should I use to store my paths? 2. How do I get the path into an object that I can use? I can clip images to a path by using the addClip method on the NSBezierPath. Are there any easy ways of calculating the points on the path as a function of the distance from the start of the path? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: How to import drawing paths into a Cocoa application?
On 22 Apr 2008, at 10:23 am, Steve Weller wrote: Are there any easy ways of calculating the points on the path as a function of the distance from the start of the path? I'm not sure about the rest of your question but I can answer this part. The short answer is no - it's really tricky. However if you have a look at my DrawKit project, it solves this problem exactly ;-) One category method on NSBezierPath I have is: - (NSPoint) pointOnPathAtLength:(float) length slope:(float*) slope; where length is the linear distance from the start of the path - it optionally also returns the slope (dy/dx) at the given point. The project is still in beta though this method is used a lot in my code and is well debugged. http://apptree.net/drawkitmain.html hth, G. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: How to import drawing paths into a Cocoa application?
Whoops, the URL should be: http://apptree.net/drawkitmain.htm On 22 Apr 2008, at 10:35 am, Graham Cox wrote: On 22 Apr 2008, at 10:23 am, Steve Weller wrote: Are there any easy ways of calculating the points on the path as a function of the distance from the start of the path? I'm not sure about the rest of your question but I can answer this part. The short answer is no - it's really tricky. However if you have a look at my DrawKit project, it solves this problem exactly ;-) One category method on NSBezierPath I have is: - (NSPoint) pointOnPathAtLength:(float) length slope:(float*) slope; where length is the linear distance from the start of the path - it optionally also returns the slope (dy/dx) at the given point. The project is still in beta though this method is used a lot in my code and is well debugged. http://apptree.net/drawkitmain.html hth, G. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/graham.cox%40bigpond.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]