Converting CGPathAddArcToPoint (or NSBezierPath equivalent) to a fixed number of CGPathAddCurveToPoint calls

  • Hi, I am using the CAShapeLayer's ability to animate a path, but the start and end path need to have the same number of segments.

    I have been using CGPathAddArcToPoint to add the curves to my path. That translates to CGPathAddCurveToPoint calls behind the scenes, but sometimes it adds one curve and sometimes two, which means that the curve can't be animated.

    I therefore need to be able to approximate the arc with the same number of CGPathAddCurveToPoint calls each time (presumably 2 or 3).

    Has anyone done this already either with CGPaths or NSBezierPaths? Any pointers would be most welcome.

    Thanks

    Gideon
  • On 30 Apr 2012, at 3:26 PM, Gideon King wrote:
    > Hi, I am using the CAShapeLayer's ability to animate a path, but the start and end path need to have the same number of segments.
    >
    > I have been using CGPathAddArcToPoint to add the curves to my path. That translates to CGPathAddCurveToPoint calls behind the scenes, but sometimes it adds one curve and sometimes two, which means that the curve can't be animated.
    >
    > I therefore need to be able to approximate the arc with the same number of CGPathAddCurveToPoint calls each time (presumably 2 or 3).
    >
    > Has anyone done this already either with CGPaths or NSBezierPaths? Any pointers would be most welcome.

    The usual way of converting circular arcs into cubic Beziers uses one curve for no more than 90 degrees of arc. Presumably calling CGPathAddArcToPoint() for less than 90 degrees will always add exactly one path segment (though this is an implementation detail of course). So you could try dividing up your arcs into a fixed number of sub-arcs so that the sub-arcs are always less than 90 degrees.
previous month may 2012 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today