Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

joining two Bézier curves smoothly (C2 continuous)

(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:

  • curve P with control points P0, P1, P2, P3
  • curve Q with control points Q0, Q1, Q2, Q3
  • if it helps, you can assume that they are already C1 continuous.

Constraints:

  • C0 continuity: P3 = Q0
  • C1 continuity: P2 - P3 = Q0 - Q1
  • C2 continuity: P1 - 2*P2 + P3 = Q0 - 2*Q1 + Q2
  • modified curves as close as possible to original curves P and Q
like image 432
palm3D Avatar asked Sep 06 '12 08:09

palm3D


1 Answers

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.

like image 122
Shuba Avatar answered Nov 19 '22 18:11

Shuba