3

我用以下代码在Objective C中绘制了一条弧线

    [newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle];

现在我想从中心到弧的两端画两条线。我怎么做?一方面,我可以使用以下代码绘制:

    [newPath lineToPoint:center];

但是另一边呢。

4

2 回答 2

4

appendBezierPathWithArcWithCenter:...绘制饼图的最简单(?)方法是使用从当前点到圆弧起点绘制一条线的事实:

// Start at the center of the circle:
[newPath moveToPoint:center];
// This draws a line from the center to the starting point of the arc AND the arc:
[newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle];
// Closing the path draws a line from the end point of the arc back to the center:
[newPath closePath];
于 2013-08-22T05:35:55.333 回答
0

我现在没有机会测试它,但你可以试试这样的东西。

#import "math.h"

[newPath moveToPoint:center];
[newPath addLineToPoint:CGPointMake(center.x + radius * cos(endAngle * M_PI / 180),
                                    center.y + radius * sin(endAngle * M_PI / 180))];

[newPath moveToPoint:center];
[newPath addLineToPoint:CGPointMake(center.x + radius * cos(startAngle * M_PI / 180),
                                    center.y + radius * sin(startAngle * M_PI / 180))];
于 2013-08-22T05:33:11.830 回答