Skip to content

Instantly share code, notes, and snippets.

View graphicore's full-sized avatar
🎯
Focusing then blurring again …

Lasse Fister graphicore

🎯
Focusing then blurring again …
View GitHub Profile
@simoncozens
simoncozens / harmonization.md
Last active October 23, 2023 06:42
Harmonizing two Bezier curves

To harmonize (with G2 curvature) two cubic Bézier curves a0,a1,a2,a3 and b0,b1,b2,b3 where a2, a3 = b0, and b1 are colinear:

  • First find d = intersection point of line a1--a2 and line b1--b2.
  • Now find ratios p0 = |a1, a2| / |a2, d| and p1 = |d1, b1| / |b1, b2|.
  • Determine ratio p = sqrt(p0 * p1)
  • Now set position of a3 = b0 such that |a2, a3| / |a3, b1| == p.
  • To do this, set t = p / (p+1).
  • Adjust the position of a3=b0 so that it sits t of the way between a2 and b1.

Of course, you may prefer to keep the position of a3 because it's the on-curve point. Fine. Instead, compute where a3 should go according to this algorithm, work out the delta between the new position and the current position, and apply that delta to the handles a2 and b1 instead.