Public
Edited
Oct 28, 2022
Importers
2 stars
Insert cell
Insert cell
parametric_plot2d((u, v) => [2 * u + v, u - v], [0, 1], [0, 1])
Insert cell
parametric_plot2d(
(r, t) => [3 * r * Math.cos(t), r * Math.sin(t)],
[1, 2],
[Math.PI / 3, (5 * Math.PI) / 3],
{ width: 640, height: 400 }
)
Insert cell
function parametric_plot2d(f, [a, b], [c, d], opts = {}) {
let {
Nu = 100, // Total number of points the u domain is broken into
nu = 10, // Number of u gridlines
Nv = 100, // Total number of points the v domain is broken into
nv = 10, // Number of v gridlines
width = 800,
height = "auto",
pad = 20,
fill = d3.schemeCategory10[9],
fillOpacity = 1,
xticks = 5,
xtickValues,
xtickFormat,
xtickSize = 6,
yticks = 5,
ytickValues,
ytickFormat,
ytickSize = 6
} = opts;

let Du = (b - a) / Nu;
let Dv = (d - c) / Nv;
let u_cut = Math.floor(Nu / nu);
let v_cut = Math.floor(Nv / nv);

let data = [];
let k = 0;
let quads = [];
let lines = [];
let boundary = [];
for (let i = 0; i <= Nu; i++) {
for (let j = 0; j <= Nv; j++) {
let u = a + i * Du;
let v = c + j * Dv;
data.push(f(u, v));
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more