Skip to content

Instantly share code, notes, and snippets.

@vasturiano
vasturiano / README.md
Last active October 22, 2017 04:11
Use the Force
@vasturiano
vasturiano / README.md
Last active October 22, 2017 04:11
Orbital Trajectory

A simulation of orbital trajectories using the d3-force simulation engine with the gravity-like d3-force-magnetic attraction force.

The initial tangential velocity of the blue orbiting body can be set relative to its orbital speed, calculated as √(GM/d). A factor of 1x (default) results in a perfectly circular orbit. Approaching the factor of √2x reaches the body's escape velocity, causing the body to drift away from the central object's gravity pull in an hyperbolic trajectory. Factors below 1 will cause a quicker fall of the blue body towards the attracting center, yielding elliptic orbits with increasing eccentricity.

The length of the pre-estimated trajectory can be manipulated by changing the number of samples (represented as dots).

See also [Force-simulated So

@vasturiano
vasturiano / README.md
Last active December 23, 2023 04:52
Dynamic 3D Graph

Graph data dynamic updates using 3d-force-graph. Clicking on a node removes it from the graph.

@vasturiano
vasturiano / README.md
Last active October 22, 2017 04:13
Pendulum

Ok, I'm confused. Why isn't energy conserved and does the pendulum eventually stop?

@vasturiano
vasturiano / README.md
Last active October 22, 2017 04:13
ForceMagnetic based Hierarchical Orbits

Simulation of multiple particles orbitting around each other in a hierarchical system (e.g. sun > planet > moon).

Uses D3's force plugin forceMagnetic to connect particles to their moving gravitational centers via magnetic/electrostatic links. These magnetic attraction forces simulate the mechanics of gravity. Each link holds its own gravitational constant to exaggerate the amplitude and velocity of the orbits relative to each other, which would be otherwise impossible in a system with a single constant.

Compare with the forceLink version.

@vasturiano
vasturiano / README.md
Last active October 22, 2017 04:14
Accretion

Simulation of accretion of particles attracted by electrostatic or gravitational forces, analogous to the interaction within dust clouds found in the early stages of star formation.

Uses D3's force plugin forceMagnetic to simulate the attraction/repulsion of objects of varying mass in an inverse-square relationship with distance. Further, particles are prevented from overlapping by applying a non-elastic collision force using forceBounce.

Using the slider controls you can add/remove particles to the system, and regulate the ratio of attractive (green attracts all other) vs repellent (red repels all other).

@vasturiano
vasturiano / .block
Last active December 12, 2020 18:27 — forked from mbostock/.block
Force-Directed Edge Bundling (FDEB) on Force-Directed Graph
license: gpl-3.0
height: 600
@vasturiano
vasturiano / README.md
Last active March 11, 2023 10:10
Entropy

Simulation of collision between moving particles with different masses inside a container, using the d3-force physics engine.

Uses two elastic collision forces, d3.forceBounce to handle elastic collisions between nodes, and d3.forceSurface for collisions with the container walls.

You can reduce the elasticity (coefficient of restitution) of the particles using the slider on the upper-left, causing kinetic energy to be lost at every collision. Elasticity of 1 indicates a pure elastic collision, while a value of 0 will cause particles to stick to each other along the collision axis.

@vasturiano
vasturiano / README.md
Last active October 22, 2017 04:15
Collision Forces Comparison
@vasturiano
vasturiano / index.html
Last active October 10, 2021 13:45
Newton's Cradle
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/4.8.0/d3.min.js"></script>
<script src="//unpkg.com/d3-force-bounce"></script>
<script src="//unpkg.com/d3-force-constant"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<svg id="canvas">