Getting a CGPoint on a UIBezierpath

送分小仙女□ 提交于 2019-12-11 04:14:49

问题


In my app I have a MKOverlayPathView where I draw a QuadCurve between two points which works just fine. Here is the code I use:

MKMapPoint mkDepPoint = MKMapPointForCoordinate([(RoutePath *)self.overlay startCoordinate]);
MKMapPoint mkArrPoint = MKMapPointForCoordinate([(RoutePath *)self.overlay endCoordinate]);
CGPoint dePoint = [self pointForMapPoint:mkDepPoint];
CGPoint arrPoint = [self pointForMapPoint:mkArrPoint];

CGPoint s = depPoint;
CGPoint e = arrPoint;

... some awesome code ...

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:s];
[path addQuadCurveToPoint:e controlPoint:cp1];
[path closePath];

Now I want to get a CGPoint for a specific percentage on that curve. I have been trying out a lot but I'm just not getting anwyhere useful. I have been trying this out but it's not really working:

CGPoint point = 
    CGPointMake(
    [self quadBezierForPercent:percent StartPoint:s.x ControlPoint:cp1.x EndPoint:e.x],
    [self quadBezierForPercent:percent StartPoint:s.y ControlPoint:cp1.y EndPoint:e.y]
);

Using this:

-(float)quadBezierForPercent:(float)t StartPoint:(float)start ControlPoint:(float)c1 EndPoint:(float)end {

    CGFloat t_ = (1.0 - t);
    CGFloat tt_ = t_ * t_;
    CGFloat tt = t * t;

    return start * tt_
    + 2.0 *  c1 * t_ * t
    + end * tt;
}

Some points in the right direction would be really helpful. Thanks a lot in advance!

来源:https://stackoverflow.com/questions/20695223/getting-a-cgpoint-on-a-uibezierpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!