• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Travelling along an NSBezierCurve in small increments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Travelling along an NSBezierCurve in small increments


  • Subject: Re: Travelling along an NSBezierCurve in small increments
  • From: Nicko van Someren <email@hidden>
  • Date: Tue, 22 Mar 2005 17:51:31 +0000

On 22 Mar 2005, at 17:20, Rick Hoge wrote:

I am trying to sample an image along an NSBezierCurve drawn by the user. In general the curve could consist of distant elements connected by smooth lines using control points. Is there any clean/simple way to obtain the x,y coordinates along such a curve at small increments along the path? I can think of a number of brute force methods that should work but want to make sure I'm not missing any nice functionality provided by the framework to do this.

Thanks for any suggestions,

The easiest way to do this is going to be to do something like the code below.


	Nicko

#import <math.h>
// Start with these two numbers
NSBezierPath *myPath;
double accuracy;

NSBezierPath *temp;
NSPoint here, delta;
int i, j, m, n;
NSPoint p[3];

[myPath setFlatness: accuracy];
temp = [myPath bezierPathByFaltteningPath];

n = [temp elementCount];

// This should not matter but might be needed to suppress a compiler warming about uninitialised variables.
x = y = 0.0;


for(i=0; i<n; i++){
NSBezierPathElement e = [myPath elementAtIndex: i associatedPoints: p];
switch(e) {
case NSMoveToBezierPathElement:
here = p[0];
ExamineImageAtPoint(here); ///// Do your stuff here
break;
case NSLineToBezierPathElement:
m = (int)(sqrt((p[0].x - here.x)*(p[0].x - here.x) + (p[0].y - here.y)*(p[0].y - here.y)) / accuracy);
delta.x = (p[0].x - here.x) / m;
delta.y = (p[0].y - here.y) / m;
m--;
for(j=0; j<m; j++) {
here.x += delta.x;
here.y += delta.y;
ExamineImageAtPoint(here); ///// Do your stuff here
}
here = p[0];
ExamineImageAtPoint(here); ///// Do your stuff here
break;
case NSCurveToBezierPathElement:
NSLog(@"This should never happen as we flattened the path");
// Follow-on...
case NSClosePathBezierPathElement:
break;
}
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Travelling along an NSBezierCurve in small increments (From: Rick Hoge <email@hidden>)

  • Prev by Date: Re: Travelling along an NSBezierCurve in small increments
  • Next by Date: Round Buttons Accept Mouse Presses Outside Visible Area
  • Previous by thread: Re: Travelling along an NSBezierCurve in small increments
  • Next by thread: Round Buttons Accept Mouse Presses Outside Visible Area
  • Index(es):
    • Date
    • Thread