开发者

Draw a bezier curved line based off three points?

开发者_运维技巧

How would I go about drawing a UIBezierpath to connect three points. I know that there must be a formula/algorithm, but I've been searching and can not find it. Would somebody be able to help me with some code for drawing a bezier curved line through three points. If you give the formula without code that will also be helpful. Just so it's easy to understand: start = start point, cp1 = 1st control point, cp2 = 2nd control point, end = end point.

Thanks in advance


This is unfortunately not the simplest of things to do, so if possible, I'd search around for some code that solves the equations for you (which are out there, trust me).

That being said, what you need to do is derive an equation based on your points. The most likely equation to use would be quadratic, so you will have y = ax^2 + bx + c. Using your three points, you will plug the x and y from each into the formula. You can then localize the functions to find the values from a, b, and c. Once you find those points, you have a full equation for your three points.

This is how you would solve it yourself in a purely mathematical form, though it seems like there are some internal methods you can use to simplify things (my background is physics, so I jumped the gun and just went straight to math before searching documentation). In the UIBezierPath Class Reference, you should be able to use either - (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2 or - (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint to get the desired effect. The latter is the method that will solve the equation I explained above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜