Re: How to get the stroke geometry of a NSBezierPath?
Re: How to get the stroke geometry of a NSBezierPath?
- Subject: Re: How to get the stroke geometry of a NSBezierPath?
- From: Mark Onyschuk <email@hidden>
- Date: Mon, 5 Feb 2007 18:50:16 -0500
(copied, minus graphic, plus a few more words, for benefit of the list)
On 4-Feb-07, at 5:56 PM, Jesse Grosjean wrote:
I'm trying to find the point where a given line intersects a
NSBezierPath, and I'd like to also include the paths current stroke
in this calculation. I know how to do it without taking the stroke
into consideration by using [NSBezierPath-OAExtensions
intersectionWithLine:lineStart:lineEnd:] from the Omni frameworks,
but that method ignores the paths current stroke.
I think the easiest way to solve this is to find a way to turn the
path's stroke into a path itself, and then just use the same test
on that path. (if there's a better way please let me know) And so
that lead to my question, how can I get and access the stroke
geometry from a NSBezierPath.
You might try a geometric approach to solving the problem:
1. find the calculated intersection as you describe above.
2. calculate a normal for the line at that point. I'm not sure
whether Omni's library provides normal calculation along a bezier,
but it's pretty straightforward and can be gleaned using the same
technique as is used to calculate an intercept: progressively split
the bezier into "flatter and flatter" line segment approximations,
then locate the intercept by doing a straight-line intercept
calculation with the appropriate split segment.
3. given the line width (actually, given 1/2 the line width, since a
stroke is applied equidistantly to either side of the conceptual
line), step back to the edge from the standard intersection point. To
do this: conceptualize a right triangle whose hypotenuse is your own
line pointing in towards the calculated intersection point. The
adjacent side is the normal from the calculated intercept and has a
length of 1/2 line width. SOHCAHTOA (man, that brings back memories
of HS math) gives us: cos theta = adjacent / hypotenuse.
so your hypotenuse length is (1/2 line width) / (cos theta)
-Mark
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden