Given an X, how can you get the Y value on a CGPathRef?

201 views Asked by At

I'm dealing with a CGPathRef that is a Bezier Curve. I'd like to get 100 evenly spaced X, Y coordinates on the path ref.

For instance, on this line, I'd like to get 100 Y values for evenly spaced X values.

CGPathRef Currently, I am creating a UIView and animating it with speed = 0.f then waiting for animation did stop and then getting the view's x,y coordinates:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationLinear;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.speed = 0.f;
pathAnimation.duration = 100;
// Get position 50
pathAnimation.timeOffset = 50;
pathAnimation.path = path;
pathAnimation.delegate = (id)self;

However, this has very poor performance when it's done a lot -- not to mention it's incredibly hacky. Is there a better way to do this?

0

There are 0 answers