General description of the problem:
Dividing P0 and P3 to break up one cubic bezier curve into two connected curves, keeping the same curve visually.
A sequence with cubic bezier curves, three in the images below, where P0 and P3 are 'anchors' and P1 is the 'head' of P0 and P2 is the 'tail' of P3. The head and tail are black in colour. The head and tail are used as P1 and P2. The head and tail are treated as directional vectors but passed in as global positions.
An infinite number of points can be found by passing in 0 < t < 1 into the below function.
public Vector3 CubicBezierCurve(float t, Vector3 P0, Vector3 P1, Vector3 P2, Vector3 P3);
{ // B(t) = (1-t)³P0 + 3(1-t)²tP1 + 3(1-t)t²P2 + t³P3
// Optimisation for speed needed
return Mathf.Pow(1 - t, 3) * P0
+ 3 * Mathf.Pow(1 - t, 2) * t * P1
+ 3 * (1 - t) * Mathf.Pow(t, 2) * P2
+ Mathf.Pow(t, 3) * P3;
}
To 'divide' P0 and P3 you can get the position of the red dot (with arrow) with the cubic bezier function where t = 0.5 and passing in Pn where n goes from 0 to 3. This division will cause a new curve between Bezier Curve 1 and 2 and the red dot will be P3 of the first curve but also P0 of the new curve.
The problem:
How to calculate the direction, which should be the red arrow, of the head of the newly created point at the red dot, and so the tail too. This while keeping the same visual curve, an error marge is accaptable.
Having tried:
- Google ofcourse, not found anything.
- Tried to determine the direction with segments, same way used to create the points to draw the curve but not giving satisfying results.