3

drawRect メソッドを使用して UIView に円を描いています。次のコードを使用して描画しています。

- (void)drawRect:(CGRect)rect
{
     CGContextRef context = UIGraphicsGetCurrentContext();
     CGContextAddArc(context, 105, 105, 55, [self convertDegreeToRadian:15.0], [self convertDegreeToRadian:345.0], 0);
     CGColorRef black = [[UIColor blackColor] CGColor];
     CGContextSetStrokeColorWithColor(context, black);
     CGContextStrokePath(context);
}

これにより、15 度から 345 度までの曲線が得られます。したがって、この曲線はある点から別の点に描かれています。2 つのエッジのポイントを取得する必要があります。どうすれば入手できますか?

4

1 に答える 1

7

円周上の点を計算する場合は、この関数が役立ちます。これは a を返し、CGPointわかりやすいパラメータを取ります。円の中心点、円の半径、ラジアン単位の回転角度。

- (CGPoint)pointAroundCircumferenceFromCenter:(CGPoint)center withRadius:(CGFloat)radius andAngle:(CGFloat)theta
{
    CGPoint point = CGPointZero;
    point.x = center.x + radius * cos(theta);
    point.y = center.y + radius * sin(theta);

    return point;
}
于 2013-08-08T13:42:09.013 に答える