Public
Edited
Nov 20, 2024
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
nodes = {
return parseBodies(solarSystem);

function parseBodies(bodies, parentMass = 0, posOffset = [0,0], velocityOffset = [0,0]) {
return [].concat(...bodies.map(body => {
const ang = (body.phase || (Math.random() * 360)) * Math.PI/180, // Random init angle if not specified (to prevent aligned init forces from distorting orbits)
x = posOffset[0] + au(body.distance) * Math.sin(ang),
y = posOffset[1] - au(body.distance) * Math.cos(ang),
relVelocity = (body.distance ? Math.sqrt(pxG * parentMass / au(body.distance)): 0) * (body.factorV || 1), // orbital velocity: sqrt(GM/d)
vx = velocityOffset[0] + relVelocity * Math.cos(ang),
vy = velocityOffset[1] + relVelocity * Math.sin(ang);

return [{
name: body.name,
symbol: body.symbol || null,
color: body.color || 'darkgrey',
r: au(body.r || Math.cbrt(body.mass)),
mass: body.mass, // mass in solar masses
x: x, // radius, distance & velocity in AUs
y: y,
vx: vx,
vy: vy,
trail: [] // Store previous positions
},
...parseBodies(body.satellites || [], body.mass, [x,y], [vx,vy])
]
}));
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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