title: How do I find the control points for a Bezier curve?
body: <p>I need to implement connections in the form of curved lines in C# (Unity). I would like to get the result as similar as possible to the implementation in Miro.com (see screenshot).</p>
  <p>After attaching the curve, I calculate the path of the cubic Bezier curve. For this first segment, the anchor points and offsets from the objects it connects are used. There are no problems at this stage.</p>
  <p><strong>Problem</strong>: When dividing the curve into segments by clicking and dragging one of the blue points of the segment (see screenshot), it is split in two in the middle. At the junction of two new curves, a new interactive (movable) point is formed for which the tangent and coordinates of the control points are unknown. I need to find the position of these control points every time the position of the interactive points changes (white points in the picture below). Moreover, the curve should not drastically change its position when dividing, not form loops, have different lengths of control point vectors (I'm not sure here) and behave as adequately as possible (like on the board in Miro).</p>
  <p>By control points I mean 2 invisible guide points for the Bezier segment.</p>
  <p>In black I painted the known control points, and in red those that I need to find. (Pn - interactive points, Cn - control points)
  <a href="https://i.stack.imgur.com/b8Jpi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b8Jpi.png" alt="Curved connection in Miro.com" /></a></p>
  <p>The algorithms I have tried to find them give incorrect distances and directions of control points.</p>
  <p>The following algorithms were tested:</p>
  <ol>
  <li>Interpolation from <a href="https://github.com/bluescan/bezier/blob/7287a5da0dee6db5f706e423375d83686da80c3c/Bezier.cs" rel="nofollow noreferrer">Tacent</a> - jumps of the curve when separating, inappropriate direction and amount of indentation of control points;</li>
  <li>Chaikin's algorithm - curve jumps during separation, creates loops;</li>
  <li>&quot;Custom&quot; interpolation based on guesses (takes into account the distance to the center of the segment between the start and end points of the segment, as well as the direction between the start and end points) - has all the same problems, but looks slightly better than those above.</li>
  </ol>
  <p>I suspect the solution is to chordally interpolate the points using a Catmull-Rom spline and translate the result to points for a Bezier curve. However, there are still problems with implementation.</p>
  <p>The curves from 3DMax also look very similar. In their documentation, I found only a mention of the parametric curve.</p>
  <p><img src="https://i.stack.imgur.com/3Wtqp.png" alt="Curve in 3DMax" />
  <img src="https://i.stack.imgur.com/irW4s.png" alt="Same curve in Miro" /></p>
  <p>Methods that I did not use (or did not work):</p>
  <ol>
  <li>Catmull-Rom interpolation;</li>
  <li>B-spline interpolation;</li>
  <li>Hermitian interpolation;</li>
  <li>De Casteljau's algorithm (although it seems not for this)</li>
  </ol>
  <p>I would be immensely grateful for any help, but I ask for as much detail as possible.</p>