また、これを行う方法が他にあるかどうかわかりません。どんな助けでも大歓迎です。 ありがとう

追加された 著者 Harsh,
これは参考になるかもしれませんが、UIBezierPathを個々のパスに分解する方法を示しています: stackoverflow.com/questions/3051760/…
追加された 著者 titaniumdecoy,

1 答え

これを行うには、 de Casteljau アルゴリズムを使用します。あなたが本当にそれの数学に入っているなら、ウィキペディアのページをチェックしてください。それは実際には非常に単純なときにそれはおそらく何よりもあなたを混乱させる数学にはありません...

  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