I have a cubic Bezier curve subdivided to two cubic Bezier: Assuming that "t_cut" is the t value where this initial Bezier is cut: example of function subdivision(BezierCurve initialCurve, Beziercurve b1, BezierCurveb2, float t_cut)
I want to retrieve the initial Bezier curve (so, its P1 and P2 control points, because P0 and P3 are known, using this function for example: BezierCurve merge(bezier1, bezier2, t_cut)). I can fix my problem if t_cut is always 0.5 (see my first question about merging two Bezier curves: Merge two or more cubic Bézier curves for optimization) but with other value of t_cut, I am not really satisfied by the result because I work with 10^-5m.
But, If someone could help me to retrieve this value of t_cut, on where the initial curve is cut, I can use this to merge the 2 curves and get an almost perfect approximation of the original curve. The merge function:
void BezierCurve::merge(QVector<BezierCurve> b_cContainer)
{
if(b_cContainer.empty()== false && b_cContainer.size() < 2)
{
QMessageBox::warning(0, "Warning", "2 or more curves are required to be merged");
}
auto leftCurve = b_cContainer[0];
auto rightCurve = b_cContainer[1];
auto A = leftCurve.getOrigin();
auto B = leftCurve.getC1();
auto C = leftCurve.getC2();
auto D = leftCurve.getEnd();
auto E = rightCurve.getC1();
auto F = rightCurve.getC2();
auto G = rightCurve.getEnd();
// origin and end do not changed: i-e A and G
origin = leftCurve.getOrigin();
end = rightCurve.getEnd();
auto k = (float)(norm(E-D))/(float)(norm(D-C));
c1 =(1+k)*B - k*A; //C1 is the first control point.
c2 =((1+k)*F - G)/k; // C2 is the second control.
}
Thank's for help.

If you know that the two curves you have resulted from splitting a single initial curve, then you don't need both these curves; knowing either and the cut position is enough to restore the full initial curve.
Have a look at this post on Stack Overflow. It discusses how you cut a curve. What you want to do is do the reverse. To find control points $Q_i$ for the segment between $t_0$ and $t_1$ (with $u_0=1-t_0$ and $u_1=1-t_1$) of a Bézier curve, you do the following computation:
\begin{align*} Q_1 &= u_0u_0u_0\,P1 + (t_0u_0u_0 + u_0t_0u_0 + u_0u_0t_0) P_2 + (t_0t_0u_0 + u_0t_0t_0 + t_0u_0t_0) P_3 + t_0t_0t_0\,P_4 \\ Q_2 &= u_0u_0u_1\,P1 + (t_0u_0u_1 + u_0t_0u_1 + u_0u_0t_1) P_2 + (t_0t_0u_1 + u_0t_0t_1 + t_0u_0t_1) P_3 + t_0t_0t_1\,P_4 \\ Q_3 &= u_0u_1u_1\,P1 + (t_0u_1u_1 + u_0t_1u_1 + u_0u_1t_1) P_2 + (t_0t_1u_1 + u_0t_1t_1 + t_0u_1t_1) P_3 + t_0t_1t_1\,P_4 \\ Q_4 &= u_1u_1u_1\,P1 + (t_1u_1u_1 + u_1t_1u_1 + u_1u_1t_1) P_2 + (t_1t_1u_1 + u_1t_1t_1 + t_1u_1t_1) P_3 + t_1t_1t_1\,P_4 \end{align*}
If you know all the $t_i$ and $u_i$ then this is simply a linear transformation, which you can express by a $4\times 4$ matrix. This matrix will turn a set of $P_i$ into a set of corresponding $Q_i$. So if you want to do the reverse operation, you need the inverse of that matrix. Compute that, feed in the $Q_i$ control points of one part of the split curve, and you obtain the control points of the full curve.
Note that if you consider the first part of the original curve, from $t=0$ to $t=t_{\text{cut}}$, then you have
$$t_0=0\quad u_0=1\quad t_1=t_{\text{cut}}\quad u_1=1-t_{\text{cut}}$$
If you don't know $t_{\text{cut}}$, then you will need to obtain that from the curve. In that case I suggest you extend one of your curves until it reaches the endpoint of the other. If you plug the $x$ coordinate of one endpoint into the equation of the cubic Bézier curve, then this is a cubic equation which will have up to three possible solutions. Try these three $t$ values and see for which the $y$ coordinate matches as well. You might want to enforce $t>1$ as well, so you really extend the curve. Then use this $t$ as $t_1$ and with $t_0=0$ do the above (forward, not inverse) computation to compute the control points of the full curve from those of the first part.