+ // http://schepers.cc/getting-to-the-point
+ function catmullRom2bezier(crp) {
+ var d = [];
+ for (var i = 0, iLen = crp.length; iLen - 2 > i; i += 2) {
+ var p = [{x: +crp[i], y: +crp[i + 1]},
+ {x: +crp[i], y: +crp[i + 1]},
+ {x: +crp[i + 2], y: +crp[i + 3]},
+ {x: +crp[i + 4], y: +crp[i + 5]}];
+ if (iLen - 4 == i) {
+ p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
+ p[3] = p[2];
+ } else if (i) {
+ p[0] = {x: +crp[i - 2], y: +crp[i - 1]};
+ }
+ d.push(["C",
+ (-p[0].x + 6 * p[1].x + p[2].x) / 6,
+ (-p[0].y + 6 * p[1].y + p[2].y) / 6,
+ (p[1].x + 6 * p[2].x - p[3].x) / 6,
+ (p[1].y + 6*p[2].y - p[3].y) / 6,
+ p[2].x,
+ p[2].y
+ ]);
+ }
+
+ return d;
+ }