Drawing a bezier curve between a set of given points

后端 未结 6 1659
春和景丽
春和景丽 2021-02-13 13:40

What is the best way to draw a bezier curve, in iOS application, that passes through a set of given points

6条回答
  •  名媛妹妹
    2021-02-13 14:24

    I know this might be late, but just for anyone who is looking for the right answer. Instead of using addLineToPoint to draw the straight line. You can use addCurveToPoint to draw the curve. e.g.

    [bezierPath moveToPoint:CGPointMake(0, 0)];
    [bezierPath addCurveToPoint:CGPointMake(40, 100) 
                  controlPoint1:CGPointMake(20, 0) 
                  controlPoint2:CGPointMake(20, 100)];
    [bezierPath addCurveToPoint:CGPointMake(80, 50) 
                  controlPoint1:CGPointMake(60, 100) 
                  controlPoint2:CGPointMake(60, 50)];
    
    // and you may don't want to close the path
    // [bezierPath closePath];
    

    It's really up to you to choose the control points of the curve. I just use the x = last_point_x + 20; y = last_point_y for control point one, and x = current_point_x - 20; y = current_point_y;

    and you may want to use other value instead of the 20 as you may have different segment width of the curve.

提交回复
热议问题