Flow fields

The Lorenz attractor

Two nearby starting points trace the wings of the Lorenz butterfly. The blue and yellow traces start almost together and separate as the solutions evolve. Orbit the camera to see the depth of each wing.

Loading Ebi…
fn lorenz(x: Number, y: Number, z: Number): List<Number, 3> {
    return [10 * (y - x), x * (28 - z) - y, x * y - 8 * z / 3]
}

let ax = ThreeDAxes(x_range=[-32, 32, 8], y_range=[-40, 40, 10], z_range=[0, 52, 10],
    x_length=440pt, y_length=400pt, z_length=215pt)
let blue = Color("blue2")
let gold = Color("yellow2")
let left = ax.streamline(lorenz, seed=[10, 10, 10], dt=0.02, steps=1000, stride=2,
    fill=blue, stroke_width=1.2pt)
let right = ax.streamline(lorenz, seed=[10, 10, 10.001], dt=0.02, steps=1000, stride=2,
    fill=gold, stroke_width=1.2pt)

mut heading = -45deg
sig camera = Camera3D(azimuth=heading, elevation=19deg)

<Scene3D camera={camera}>
    {ax.frame(fill=Color("dark2"), stroke_width=0.8pt)}
    {left}{right}
    {Scatter3D([point_on_path3d(left, 1)], radius=2.4pt, fill=blue)}
    {Scatter3D([point_on_path3d(right, 1)], radius=2.4pt, fill=gold)}
</Scene3D>
animate(heading, to=315deg, duration=12s, ease="linear")

ax.streamline integrates the field from one seed. Use ax.streamlines(f, seeds=...) to start several paths with the same style. dt sets the integration step, steps gives the number of steps, and stride controls which integration samples become anchors for the smooth curve. StreamlineFlash takes a path and a progress signal from 0 to 1. Use span=1 to draw the entire trace before erasing it from the starting point. point_on_path3d samples a world position on the curve, as shown by the markers at the endpoints.

See Vector fields to show the flow direction at points on a grid.