0

我用下面的代码制作了Circle

//Color Declaration
    UIColor *color = [UIColor colorWithRed:0 green:0.429 blue:0 alpha:1];

    //Drawing Circle
    CGRect circleRect = CGRectMake(20, 20, 170, 170);
    UIBezierPath *circlePath = [UIBezierPath bezierPath];
    [circlePath addArcWithCenter:CGPointMake(CGRectGetMidX(circleRect), CGRectGetMidY(circleRect))
                          radius:CGRectGetWidth(circleRect)/2 startAngle:0 * M_PI/180
                        endAngle:289 * M_PI/180
                       clockwise:YES];
    [circlePath addLineToPoint:CGPointMake(CGRectGetMidX(circleRect), CGRectGetMidY(circleRect))];
    [circlePath closePath];


    [color setFill];
    [circlePath fill];

我已经使用下面的代码验证了带有圆形区域的触摸代码,

- (BOOL)validatePoint:(CGPoint)myPoint
{
    // calculate how far from centre we are with Pythagorean
    // √ a2 + b2
    CGFloat a = abs(myPoint.x - (self.view.bounds.size.width/2));
    CGFloat b = abs(myPoint.y - (self.view.bounds.size.height/2));
    CGFloat distanceFromCentre = sqrt(pow(a,2) + pow(b,2));

    if((distanceFromCentre > self.minRadiusSize) && (distanceFromCentre < self.maxRadiusSize)){
        return YES;
    }else{
        // not inside doughnut
        return NO;
    }
}

我已经用上面的代码验证了圆。当上面的代码为真时,我们可以向圆添加触摸。

同样,我必须验证圆的扇区(部分)。
我的要求是,我必须验证圈子。我是否必须检测绘制圆的扇区(部分)。我有公式
[Area of Sector = ½ × (θ × π/180) × r2 (when θ is in degrees)]

4

1 回答 1

0

如果您要做的只是检查该点是否在圆形扇区内,那么您应该使用相同的路径来测试该点

BOOL isInsideSector = [circlePath containsPoint:myPoint];
于 2013-08-19T12:48:54.787 回答