根据三个点绘制贝塞尔曲线?

发布于 2024-12-08 17:06:17 字数 174 浏览 1 评论 0原文

我将如何绘制 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2024-12-15 17:06:17

不幸的是,这不是最简单的事情,所以如果可能的话,我会寻找一些可以为您求解方程的代码(这些代码就在那里,相信我)。

话虽这么说,你需要做的是根据你的观点推导出一个方程。最有可能使用的方程是二次方程,因此您将得到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文