| 5 | // --------------------------------------------------------------------------- |
| 6 | |
| 7 | function catmullRom(p0, p1, p2, p3, t) { |
| 8 | const t2 = t * t; |
| 9 | const t3 = t2 * t; |
| 10 | return { |
| 11 | x: |
| 12 | 0.5 * |
| 13 | (2 * p1.x + |
| 14 | (-p0.x + p2.x) * t + |
| 15 | (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + |
| 16 | (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3), |
| 17 | y: |
| 18 | 0.5 * |
| 19 | (2 * p1.y + |
| 20 | (-p0.y + p2.y) * t + |
| 21 | (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + |
| 22 | (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3), |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | function interpolateSpline(controlPoints, numSamples) { |
| 27 | if (controlPoints.length === 0) return []; |