简体   繁体   English

绘制基于三个点的贝塞尔曲线?

[英]Draw a bezier curved line based off three points?

How would I go about drawing a UIBezierpath to connect three points. 我将如何绘制UIBezierpath来连接三个点。 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. 这样就很容易理解:开始=起点,cp1 =第一个控制点,cp2 =第二个控制点,结束=终点。

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. 最可能使用的方程是二次方程,因此您将拥有y = ax ^ 2 + bx + c。 Using your three points, you will plug the x and y from each into the formula. 使用您的三个点,将x和y分别插入公式中。 You can then localize the functions to find the values from a, b, and c. 然后,您可以本地化函数以从a,b和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. UIBezierPath类参考中 ,您应该可以使用- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint以获得所需的效果。 The latter is the method that will solve the equation I explained above. 后者是解决上述方程式的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM