Vector fields

ax.vector_field uses the same kind of callback as streamlines. It samples a grid and draws an arrow from each sample point. Arrow3D(start, end) places an individual arrow in world coordinates.

Loading Ebi…
fn twist(x: Number, y: Number, z: Number): List<Number, 3> {
    let radius_squared = x * x + y * y
    return [-y, x, radius_squared / (1 + radius_squared)]
}

let ax = ThreeDAxes(x_range=[-2, 2, 2], y_range=[-2, 2, 2], z_range=[-2, 2, 2],
    x_length=150pt, y_length=150pt, z_length=150pt)
let field = ax.vector_field(twist, samples=2, vector_scale=0.38, fill=Color("blue2"))
let up = Arrow3D([0pt, 0pt, -74pt], [0pt, 0pt, 93pt], stroke_width=2pt, fill=Color("orange3"))
mut heading = -65deg
sig camera = Camera3D(azimuth=heading, elevation=28deg)
<Scene3D camera={camera}>{field}{up}</Scene3D>
animate(heading, to=295deg, duration=8s, ease="linear")

Arrows shorten smoothly as their length approaches the grid spacing. Set max_length for a specific size limit or use vector_scale to change their lengths together. See Plot for surfaces and camera transitions.