phQuinticSpline

fun List<Vector2>.phQuinticSpline(closed: Boolean): List<PHQuintic>(source)

The C2 interpolating spline of PH quintics through this polyline, one per edge, after Albrecht and Farouki, "Construction of C2 Pythagorean-hodograph interpolating splines by the homotopy method" (Advances in Computational Mathematics, 1996).

Every edge i gets the preimage w(t) with coefficients (zi-1 + zi) / 2, zi and (zi + zi+1) / 2, which makes w C1 and therefore the spline C2. Each edge ending at its point is a complex quadratic equation, 3zi-1² + 27zi² + 3zi+1² + 13zi-1zi + 13zizi+1 + zi-1zi+1 = 60(pi - pi-1), solved by Newton's method from zi = √(pi - pi-1), with signs chosen so that neighbouring z point the same way. Open splines take z0 = z1 and zn+1 = zn, which gives zero curvature at the ends. Closed splines take zn+1 = ±z1: w turns by half the turning of the tangent, so for curves that turn an odd number of times, every simple closed curve among them, w has to change sign once around the loop.

When Newton's method doesn't converge, which happens for erratic points, every edge is the phQuinticHermite interpolant with Catmull-Rom derivatives instead, which still passes through all points but is only C1.

Returns an empty list when there are fewer than two distinct points, or three for closed polylines.