Published
Edited
May 20, 2018
Importers
11 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof curve_bez = new View([[241,63],[615,250],[14,210],[400,61]])
Insert cell
Insert cell
Insert cell
bez3_to_cheb = function bez3_to_cheb([b0, b1, b2, b3]) {
const denom = 1/32;
const [b00, b01] = b0, [b10, b11] = b1, [b20, b21] = b2, [b30, b31] = b3;
return [
[ ( 10*b00 + 6*b10 + 6*b20 + 10*b30) * denom,
(-15*b00 - 3*b10 + 3*b20 + 15*b30) * denom,
( 6*b00 - 6*b10 - 6*b20 + 6*b30) * denom,
( -b00 + 3*b10 - 3*b20 + b30) * denom],
[ ( 10*b01 + 6*b11 + 6*b21 + 10*b31) * denom,
(-15*b01 - 3*b11 + 3*b21 + 15*b31) * denom,
( 6*b01 - 6*b11 - 6*b21 + 6*b31) * denom,
( -b01 + 3*b11 - 3*b21 + b31) * denom]];
}
Insert cell
cheb_to_bez3 = function cheb_to_bez3([c0, c1]) {
const denom = 1/3;
const [c00, c01, c02, c03] = c0, [c10, c11, c12, c13] = c1;
return [
[ (c00 - c01 + c02 - c03),
(c10 - c11 + c12 - c13)],
[ (3*c00 - c01 - 5*c02 + 15*c03) * denom,
(3*c10 - c11 - 5*c12 + 15*c13) * denom],
[ (3*c00 + c01 - 5*c02 - 15*c03) * denom,
(3*c10 + c11 - 5*c12 - 15*c13) * denom],
[ (c00 + c01 + c02 + c03),
(c10 + c11 + c12 + c13)]];
}
Insert cell
Insert cell
// coeffs2vals of length 4 but taking 2 lists of coefficients as inputs,
// returning 4 separate coordinate pairs, and with less overhead.
// We could save more work by not doing a full matrix multiplication but
// the code would get more complicated, and this is plenty fast.
cheb3_to_pts = function cheb3_to_pts([c0, c1]) {
const [c00, c01, c02, c03] = c0, [c10, c11, c12, c13] = c1;
return [
[( c00 - c01 + c02 - c03), ( c10 - c11 + c12 - c13)],
[( c00 - .5*c01 - .5*c02 + c03), ( c10 - .5*c11 - .5*c12 + c13)],
[( c00 + .5*c01 - .5*c02 - c03), ( c10 + .5*c11 - .5*c12 - c13)],
[( c00 + c01 + c02 + c03), ( c10 + c11 + c12 + c13)]];
}
Insert cell
// vals2coeffs of length 4 but taking 4 coordinate pairs as input
// and returning a pair of lists of coefficients
pts_to_cheb3 = function pts_to_cheb3([v0, v1, v2, v3]) {
const denom = 1/6;
const [v00, v01] = v0, [v10, v11] = v1, [v20, v21] = v2, [v30, v31] = v3;
return [
[ ( v00 + 2*v10 + 2*v20 + v30) * denom,
(-2*v00 - 2*v10 + 2*v20 + 2*v30) * denom,
( 2*v00 - 2*v10 - 2*v20 + 2*v30) * denom,
( -v00 + 2*v10 - 2*v20 + v30) * denom],
[ ( v01 + 2*v11 + 2*v21 + v31) * denom,
(-2*v01 - 2*v11 + 2*v21 + 2*v31) * denom,
( 2*v01 - 2*v11 - 2*v21 + 2*v31) * denom,
( -v01 + 2*v11 - 2*v21 + v31) * denom]];
}
Insert cell
Insert cell
pts_to_bez3 = function pts_to_bez3([v0, v1, v2, v3]) {
const denom = 1/9;
const [v00, v01] = v0, [v10, v11] = v1, [v20, v21] = v2, [v30, v31] = v3;
return [
[v00, v01],
[ (-10*v00 + 24*v10 - 8*v20 + 3*v30)*denom,
(-10*v01 + 24*v11 - 8*v21 + 3*v31)*denom],
[ (3*v00 - 8*v10 + 24*v20 - 10*v30)*denom,
(3*v01 - 8*v11 + 24*v21 - 10*v31)*denom],
[v30, v31]];
}
Insert cell
bez3_to_pts = function bez3_to_pts([b0, b1, b2, b3]) {
const denom = 1/64;
const [b00, b01] = b0, [b10, b11] = b1, [b20, b21] = b2, [b30, b31] = b3;
return [
[b00, b01],
[ (27*b00 + 27*b10 + 9*b20 + b30)*denom,
(27*b01 + 27*b11 + 9*b21 + b31)*denom],
[ (b00 + 9*b10 + 27*b20 + 27*b30)*denom,
(b01 + 9*b11 + 27*b21 + 27*b31)*denom],
[b30, b31]];
}
Insert cell
Insert cell
import {evaluate as chebeval, diff, cumsum, sum, coeffs2vals, vals2coeffs, chebpts} from "@jrus/cheb"
Insert cell
import {View} from "@mbostock/synchronized-views"
Insert cell
d3 = require("https://d3js.org/d3.v5.min.js")
Insert cell
import {math_css, $, $$} with {$css as $css} from "@jrus/misc"
Insert cell
$css = html`${math_css}`
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more