通过3个NSPoints平滑曲线

时间:2016-02-19 09:43:29

标签: objective-c macos nsbezierpath

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

使用这个简单的3点代码,我可以将它们全部连接起来。这段代码的产品看起来像这样......

enter image description here

这是我用NSBezierPath绘制的唯一方法(而不是绘制圆圈)。

我想知道如何绘制一条平滑的曲线,抛出3个不同的点。这样看起来就像这样。 (RED)

enter image description here

我在网上找不到它。谢谢。

1 个答案:

答案 0 :(得分:1)

这应该可以解决问题,当然你应该使用这些值来获得所需的外观。

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];