根据三个点绘制贝塞尔曲线?
我将如何绘制 UIBezierpath 来连接三个点。我知道一定有一个公式/算法,但我一直在寻找,但找不到它。有人能够帮助我编写一些通过三点绘制贝塞尔曲线的代码吗?如果您给出不带代码的公式也会有帮助。这样很容易理解:start = 起点,cp1 = 第一个控制点,cp2 = 第二个控制点,end = 终点。
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,这不是最简单的事情,所以如果可能的话,我会寻找一些可以为您求解方程的代码(这些代码就在那里,相信我)。
话虽这么说,你需要做的是根据你的观点推导出一个方程。最有可能使用的方程是二次方程,因此您将得到 y = ax^2 + bx + c。使用这三个点,将每个点的 x 和 y 代入公式中。然后,您可以本地化函数以查找 a、b 和 c 中的值。一旦找到这些点,您就拥有了这三个点的完整方程。
这就是你如何以纯粹的数学形式自己解决它,尽管似乎有一些内部方法可以用来简化事情(我的背景是物理学,所以我在搜索文档之前就直接进入数学) 。在
UIBezierPath
类参考,您应该能够使用- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2
或- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint
以获得所需的效果。后者是求解我上面解释的方程的方法。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.