一些贝塞尔曲线的用法

  • 贝塞尔曲线画饼图中的扇形:
UIBezierPath *arcPath = [UIBezierPath bezierPath];
            [arcPath moveToPoint:CGPointMake(vFrame.size.width / 2, vFrame.size.height / 2)];
            [arcPath addArcWithCenter:CGPointMake(vFrame.size.width / 2, vFrame.size.height / 2) radius:layerRadius startAngle: - M_PI_2 + startValue * 2 * M_PI  endAngle: - M_PI_2 + endValue * 2 * M_PI clockwise:YES];
  • 贝塞尔曲线画类似抛物线的曲线有control点的
CGPoint centerPoint = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
    [lineColor set];
    UIBezierPath *path = [UIBezierPath bezierPath];
    path.lineWidth = 2.0;
    path.lineCapStyle = kCGLineCapRound;//拐角处理
    path.lineJoinStyle = kCGLineJoinRound;//终点处理
    
    [path moveToPoint:CGPointMake(arcMiddlePoint.x, arcMiddlePoint.y)];
    
    CGPoint controlPoint = CGPointZero;
    CGPoint endPoint = CGPointZero;
    
    if(arcMiddlePoint.x >= centerPoint.x && arcMiddlePoint.y <= centerPoint.y){
        //右上角
        controlPoint = CGPointMake(arcMiddlePoint.x + 10, labelFrame.origin.y);
        endPoint = CGPointMake(labelFrame.origin.x, labelFrame.origin.y + labelFrame.size.height / 2);
    }else if (arcMiddlePoint.x >= centerPoint.x && arcMiddlePoint.y > centerPoint.y){
        //右下角
        controlPoint = CGPointMake(arcMiddlePoint.x + 10, labelFrame.origin.y + 10);
        endPoint = CGPointMake(labelFrame.origin.x, labelFrame.origin.y + labelFrame.size.height / 2);
    }else if (arcMiddlePoint.x < centerPoint.x && arcMiddlePoint.y >= centerPoint.y){
        //左下角
        controlPoint = CGPointMake(arcMiddlePoint.x - 10, labelFrame.origin.y + 10);
        endPoint = CGPointMake(labelFrame.origin.x + labelFrame.size.width, labelFrame.origin.y + labelFrame.size.height / 2);
    }else{
        //左上角
        controlPoint = CGPointMake(CGRectGetMaxX(labelFrame) + 10, arcMiddlePoint.y);
        endPoint = CGPointMake(labelFrame.origin.x + labelFrame.size.width, labelFrame.origin.y + labelFrame.size.height / 2);
    }
    [path addQuadCurveToPoint:endPoint controlPoint:controlPoint];
    [path stroke];

你可能感兴趣的:(一些贝塞尔曲线的用法)