(Follow-up of this question.)
Given a sequence of cubic Bézier curves, how can I modify them minimally to make them join in a C2-continuous way?
Input:
P0
, P1
, P2
, P3
Q0
, Q1
, Q2
, Q3
Constraints:
P3 = Q0
P2 - P3 = Q0 - Q1
P1 - 2*P2 + P3 = Q0 - 2*Q1 + Q2
Getting the modified curves as close as possible to the originals can have multiple interpretations, but one could consider that keeping endpoints and tangents far from the joining points constant could fit. So the points P0
, P1
, P3 = Q0
, Q2
, Q3
are constant.
We can change the origin such that P3 = Q0 = 0
, enforcing C2 continuity can then be expressed as:
P1 - 2*P2 = 2*Q1 + Q2
One can expressP2=a*e^i*r
and Q1=b*e^i*r
in complex representations (keeping the same angle enforces C2 continuity. Compute
(P1 - Q2)/2 = c*e^i*s
Enforcing C2 continuity should be choosing r=s
, and finding a combination of a
and b
such that a+b =c
. There are infinitely many solutions, but one might use heuristics such as changing a
if it is the smallest (thus producing less sensible changes).
If that's not producing sufficiently small variations, try a two-step optimisation: first change P1
and Q2
to get s
closer to r
, then apply the steps above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With