Public
Edited
Aug 22, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
otherSystems
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
otherSystems = {
const data = [];

tArray.map((t) => {
system_vs.map((z) => {
const system = originSystem.find(
(d) => (d.name === z.name) & (d.t === t)
),
light = originSystem.find((d) => (d.name === "light") & (d.t === t)),
translate = (x, t) => {
const newT = system.length,
newX = 0,
diffT = newT - system.t2,
diffX = newX - system.x2;
return { x: x + diffX, t: t + diffT };
};

{
const d1 = translate(system.x2, system.t2),
d2 = translate(light.x2, light.t2),
{ name, ratio } = system;

data.push({
x1: 0,
t1: 0,
x2: d1.x,
t2: d1.t,
t,
name,
type: "system",
ratio
});

data.push({
x1: 0,
t1: 0,
x2: d2.x - (correctOffset ? t * speedOfLight : 0),
t2: d2.t,
t,
name,
type: "light",
ratio
});
}
});
});

return data;
}
Insert cell
originSystem
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
originSystem = {
const data = [],
c = speedOfLight;

tArray.map((t) => {
// Light
{
const x1 = 0,
t1 = 0,
x2 = c * t,
t2 = t,
name = "light";

data.push({ x1, t1, x2, t2, name, t, ratio: 1.0 });
}

// System2
function addSystem(v, name, ratio) {
const x1 = 0,
t1 = 0,
x2 = v * t,
t2 = t;

data.push({ x1, t1, x2, t2, name, t, ratio });
}

system_vs.map((d) => addSystem(d.v, d.name, d.ratio));

data.map((d) => {
const length = distance([d.x1, d.t1], [d.x2, d.t2]);
Object.assign(d, { length });
});
});

return data;
}
Insert cell
Insert cell
/**
* Distance between two points,
* a: [a.x, a.y]
* b: [b.x, b.y]
*/
distance = (a = [0, 0], b = [1, 1]) => {
return Math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2);
}
Insert cell
d3 = require("d3")
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