我的应用程序中有 UIBezierPath。当识别到路径上的手指触摸时,我想细分该曲线并将这两条曲线存储到两个不同的对象中。因此,触摸坐标将作为一条曲线的终点和第二条曲线的起点。
同样,如果我触摸这条曲线中的任何一条,该曲线将细分为另外两条曲线,依此类推。
我找了很多这个。但找不到什么好的解决办法。
我也不知道是否还有其他方法可以做到这一点。任何帮助将不胜感激。
谢谢
您可以使用德卡斯特里奥算法。如果你真的很喜欢数学在这里查看维基百科页面 http://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm,但如果你对数学不太感兴趣,它可能会让你更加困惑,因为它实际上很简单......
- 计算沿触摸曲线(0.0 到 1.0 之间)的参数化值。为此,您可以定期计算一组点(0.1、0.2、0.3 等),然后找到距离触摸点最近的两个点,如果您想要更高的精度(0.21、0.22、 0.23 等)。这将导致沿着代表您触摸位置的曲线段出现一个介于 0.0 和 1.0 之间的数字。
- This bit is difficult to explain in text, but there's a good visualization on this page http://www.caffeineowl.com/graphics/2d/vectorial/bezierintro.html 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:
- 计算沿 B→C 线的临时点 T 为 0.4
- 令A1点等于A点
- 计算沿A→B线0.4的点B1
- 计算沿 B1→T 线 0.4 的点 C1
- 令D1点等于分割点S
- 令 D2 点等于 D 点
- 计算点C2,沿C→D线为0.4
- 计算沿线 T→C2 的 B2 为 0.4
- 令A2点等于分割点S
现在您有两条新的贝塞尔曲线,第一条使用控制点 A1、B1、C1、D1,第二条使用 A2、B2、C2、D2。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)