如何从 UIBezierPath 获取点列表?
我有一个 UIBezierPath 我需要获取以下列表点来自。
在Qt
中,有一个名为pointAtPercent
的函数可以满足我的需求,但我在Objective-C
中找不到任何等效的函数。
有谁知道该怎么做?
I have a UIBezierPath that I need to take a list of points from.
In Qt
there is a function called pointAtPercent
that would fit my needs but I can't find anything equivalent in Objective-C
.
Does anyone know how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以尝试这样做:
路径应用程序函数将依次处理路径的每个路径元素。
查看 CGPathApplierFunction 和 CGPathApply。
路径应用程序函数可能看起来像这样
You might try this:
The path applier function will be handed each of the path's path elements in turn.
Check out CGPathApplierFunction and CGPathApply.
The path applier function might look something like this
@莫里茨 很好的答案!为了找到类似 Swift 的解决方案,我在这篇文章中偶然发现了一种方法,并实现了一个像这样的 CGPath 扩展来获取要点路径:
@Moritz Great answer! To find a Swift like solution I strumbled across an approach in this post and implemented a CGPath extension like this to get the points from the path:
我认为你试图做这样的事情:
https://math.stackexchange.com/questions/26846/is-there-an-explicit-form-for-cubic-bézier-curves
y=u0(1−x^3)+3u1(1−x^2)x+3u2(1−x)x^2+u3x^3< /code>
这是我打印该函数的所有值的方法。
输出是:
I think you were trying to do something like this:
https://math.stackexchange.com/questions/26846/is-there-an-explicit-form-for-cubic-bézier-curves
y=u0(1−x^3)+3u1(1−x^2)x+3u2(1−x)x^2+u3x^3
This is my method for printing all values of that function.
And output is:
我写了一篇关于查找 UIBezierPath 上最近的点的文章,其中与OP正在寻找的非常相似。我还在 Swift 上创建了一个演示项目: https://github.com/agordeev/BezierPathClosestPoint
I wrote an article about finding the closest point on UIBezierPath, which is very similar to what the OP is looking for. I've also created a demo project on Swift: https://github.com/agordeev/BezierPathClosestPoint
我已经修改了 @FBente 帖子以与 swift 3 一起使用
i have modified @FBente post to work with swift 3
迅速4.0:
swift 4.0:
更新了 FBente 的 Swift 3 扩展:
Updated FBente's extension for Swift 3: