objective-cmacosnsbezierpath

Smooth curve through 3 NSPoints


NSBezierPath *angle = [NSBezierPath bezierPath];
[angle moveToPoint: NSMakePoint(100, 50)];
[angle lineToPoint: NSMakePoint(125, 100)];
[angle lineToPoint: NSMakePoint(100, 150)];
[angle stroke];

Using this simple code of 3 points, I can connect them all. The product of this code looks like this...

enter image description here

This is the only way of drawing I know with NSBezierPath (Instead of drawing a circle).

I was wondering how to draw a smooth curve throw 3 different points. Such that it would look like this. (RED)

enter image description here

I couldn't find it on the web. Thank you.


Solution

  • This should do the trick, of course you should play with the values to get the desired look.

    NSBezierPath* bezierPath = [NSBezierPath bezierPath];
    [bezierPath moveToPoint: NSMakePoint(32.5, 16.5)];
    [bezierPath curveToPoint: NSMakePoint(60.5, 47.5) controlPoint1: NSMakePoint(32.5, 16.5) controlPoint2: NSMakePoint(57.5, 15.5)];
    [bezierPath curveToPoint: NSMakePoint(35.5, 78.5) controlPoint1: NSMakePoint(63.5, 79.5) controlPoint2: NSMakePoint(35.5, 78.5)];
    [[NSColor blackColor]setStroke];
    bezierPath.lineWidth = 1;
    [bezierPath stroke];