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 lineb1--b2
. - Now find ratios
p0 = |a1, a2| / |a2, d|
andp1 = |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 sitst
of the way betweena2
andb1
.
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.
Note: used in Glyphs.app plug-in Green Harmony and in Alex Slobzheninov’s script G2 Harmonize (install either via Window > Plugin Manager).