如何细分UIBezierPath并将其存储在两个不同的对象中

发布于 2024-12-21 21:02:16 字数 216 浏览 0 评论 0原文

我的应用程序中有 UIBezierPath。当识别到路径上的手指触摸时,我想细分该曲线并将这两条曲线存储到两个不同的对象中。因此,触摸坐标将作为一条曲线的终点和第二条曲线的起点。

同样,如果我触摸这条曲线中的任何一条,该曲线将细分为另外两条曲线,依此类推。

我找了很多这个。但找不到什么好的解决办法。

我也不知道是否还有其他方法可以做到这一点。任何帮助将不胜感激。 谢谢

I have UIBezierPath in the application. When the finger touch on the path is recognized i want to subdivide that curve and store that two curves into two different objects. So touch co-ordinates will work as end-point for one curve and start-point for second curve.

Again if i touch on any of this curve, that curve will subdivide into two other curves and so on.

I searched for this a lot. But could not find any good solution.

Also I do not have idea if there is any other way to do this. Any help would be greatly appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

倥絔 2024-12-28 21:02:16

您可以使用de Casteljau算法来做到这一点。如果您真的对数学感兴趣请查看此处的维基百科页面,但是如果你对数学不太感兴趣,当它实际上非常简单时,它可能会让你更加困惑......

  1. 沿着触摸的曲线(0.0 和 1.0 之间)计算参数化值。为此,您可以定期计算一组点(0.1、0.2、0.3 等),然后找到距离触摸点最近的两个点,如果您想要更高的精度(0.21、0.22、 0.23 等)。这将导致沿着代表您触摸位置的曲线段出现一个介于 0.0 和 1.0 之间的数字。
  2. 这一点很难用文字解释,但是此页面 大约在标题细分贝塞尔曲线下方。使用图表下方的滑块查看其工作原理,这是我的文字解释:您需要按照与步骤 1 中计算的参数化值成比例的方式细分曲线段控制点之间的直线。因此,如果您计算出 0.4,则有四个点(A、B、C、D)加上曲线上最接近您触摸的分割点(沿曲线 0.4 处),我们将此分割点称为 S:
    • 计算沿 B→C 线的临时点 T,其值为 0.4
    • 令 A1 点等于 A 点
    • 计算点 B1,即沿线 A→B 的 0.4
    • 计算点C1,沿线B1→T为0.4
    • 令 D1 点等于分割点 S
    • 令 D2 点等于 D 点
    • 计算点C2,沿线C→D为0.4
    • 计算点 B2,沿线 T→C2 为 0.4
    • 令 A2 点等于分割点 S

现在您有两条新的贝塞尔曲线,第一个使用控制点 A1、B1、C1、D1,第二个使用 A2、B2、C2、D2。

You can do this with the de Casteljau algorithm. If you're really into the maths of it check out the Wikipedia page here, but if you're not that into the maths it will probably confuse you more than anything when it's actually quite simple...

  1. Calculate the parameterized value along the curve (between 0.0 and 1.0) of the touch. To do this you can calculate a set of points at regular intervals (0.1, 0.2, 0.3 etc.) and then find the two closest points to your touch points and repeat the parameterization between these points if you want more accuracy (0.21, 0.22, 0.23, etc.). This will result in a number between 0.0 and 1.0 along the curve segment representing where you touched.
  2. This bit is difficult to explain in text, but there's a good visualization on this page about half-way down under the heading Subdividing a Bezier curve. Use the slider under the diagram to see how it works, here's my textual explanation: You need to subdivide the straight lines between the control points of your curve segment proportional to the parameterized value you calculated in step 1. So if you calculated 0.4, you have four points (A, B, C, D) plus the split-point on the curve closest to your touch at 0.4 along the curve, we'll call this split-point point S:
    • Calculate a temporary point T which is 0.4 along the line B→C
    • Let point A1 be equal to point A
    • Calculate point B1 which is 0.4 along the line A→B
    • Calculate point C1 which is 0.4 along the line B1→T
    • Let point D1 be equal to the split point S
    • Let point D2 be equal to point D
    • Calculate point C2 which is 0.4 along the line C→D
    • Calculate point B2 which is 0.4 along the line T→C2
    • Let point A2 be equal to the split point S

Now you have two new Bezier curves, the first using control points A1, B1, C1, D1 and the second using A2, B2, C2, D2.

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