Reference
Contents
Index
UniformStreamlines.ArrowDataUniformStreamlines.StreamlineDataUniformStreamlines.box_intersection!UniformStreamlines.colorizeUniformStreamlines.streamUniformStreamlines.streamarrowsUniformStreamlines.streamlinesUniformStreamlines.trace!
UniformStreamlines.ArrowData — Type
ArrowData{D}Holds arrow glyphs computed by streamarrows.
Fields
points :: Matrix{Float64}—D × Nmatrix of arrow base positions.vectors :: Matrix{Float64}—D × Nmatrix of arrow direction vectors (unit tangent scaled byscale).speeds :: Vector{Float64}— speed‖field(p)‖at each arrow, suitable for color-mapping.indices :: Vector{Int}— column indices into the originalStreamlineData.pathsmatrix, so per-vertex color arrays can be subsampled.
UniformStreamlines.StreamlineData — Type
StreamlineData{D}Holds the output of evenstream. D is the spatial dimension.
Fields
paths :: Matrix{Float64}—D × Nmatrix. Streamlines are stored column-by-column and separated by columns ofNaN. Passpaths[1,:]andpaths[2,:](andpaths[3,:]in 3-D) directly to a plotting library.lower :: Vector{Float64}— lower corner of the domain box.upper :: Vector{Float64}— upper corner of the domain box.field :: Function— the interpolated velocity functionfield(p::AbstractVector) -> Vector{Float64}. Useful for querying velocities at arbitrary points, and required internally bycolorizeandstreamarrows.
UniformStreamlines.box_intersection! — Method
box_intersection!(out, pin, pout, lower, upper)Compute the point where the segment pin → pout crosses the axis-aligned box [lower, upper] and write the result into out. Assumes pin is inside the box and pout is outside.
UniformStreamlines.colorize — Method
colorize(data::StreamlineData, f) -> VectorCompute a per-point value along the streamlines for use as a color argument to streamlines / streamlines!.
The return type matches the return type of f:
freturns aReal→Vector{Float64}(use withcolormap)freturns aColorant→Vector{<:Colorant}(used directly as color, no colormap needed)
The color function f
f has the signature
f(pos::AbstractVector, vel::AbstractVector) -> Union{Real, Colorant}where pos is the point position and vel = field(pos) is the velocity vector, both of length D.
Built-in symbols (shortcuts for scalar coloring):
| Symbol | Equivalent function |
|---|---|
:norm/:speed | (p, v) -> norm(v) |
:vx / :u | (p, v) -> v[1] |
:vy / :v | (p, v) -> v[2] |
:vz / :w | (p, v) -> v[3] (3-D only) |
:x | (p, v) -> p[1] |
:y | (p, v) -> p[2] |
:z | (p, v) -> p[3] (3-D only) |
Examples
# Scalar coloring — pair with colormap
c = colorize(str, :norm)
c = colorize(str, (p, v) -> p[1]^2 + p[2]^2) # distance² from origin
c = colorize(str, (p, v) -> v[1] / norm(v)) # cos(angle) with x-axis
streamlines!(ax, str; color=c, colormap=:viridis)
# Direct color — no colormap needed
c = colorize(str, (p, v) -> RGBAf(v[1], v[2], 0, 1)) # color by velocity direction
streamlines!(ax, str; color=c)UniformStreamlines.stream — Method
stream(Val(D), lower, upper, u; kwargs...) -> Matrix{Float64}Low-level core: compute evenly-spaced streamlines of the vector field u over the axis-aligned box [lower, upper]. Works in any dimension D (D=2 or D=3 are typical).
u must be a function u(p::AbstractVector) -> AbstractVector returning the velocity at position p.
Returns
A D × N matrix. Individual streamlines are concatenated column-by-column, separated by columns of NaN.
Keyword arguments
| Keyword | Default | Description |
|---|---|---|
min_density | 4 | Seeding grid density (domain divided into 10 × min_density cells/axis). Higher → more seed candidates → denser coverage. |
max_density | 10 | Collision grid density (domain divided into 10 × max_density cells/axis). Higher → streamlines may pass closer together. |
allow_collisions | false | If true, streamlines pass through each other instead of being truncated. |
seeds | nothing | Explicit seed points; overrides density grids. Two formats: ([x1,y1], [x2,y2], ...) (tuple of D-vectors, one per point) or (xs, ys) (pair of N-vectors, one per axis). |
min_length | 2 | Discard streamlines with fewer than this many vertices. |
stepsize | adaptive | Arc-length step size (physical distance per integration step). Velocity is normalized internally, so this controls spatial resolution independent of field magnitude. Default: min(norm(domain) / (10 × max_density × 10), 0.05). |
UniformStreamlines.streamarrows — Method
streamarrows(data::StreamlineData{D}; every=10, spacing=nothing, scale=1.0) -> ArrowData{D}Extract arrow glyphs from a StreamlineData result.
Arrows can be placed in two modes:
- Vertex mode (default) — an arrow every
everypath vertices. Fast, but non-uniform when vertex spacing varies. - Arc-length mode — an arrow every
spacingunits of arc length. Setspacingto a positive number to enable uniform placement. Whenspacingis given,everyis ignored.
Keyword arguments
every :: Int = 10— (vertex mode) place an arrow every this many path vertices.spacing :: Real = nothing— (arc-length mode) place an arrow every this many units of arc length along each streamline. Overrideseverywhen set.scale :: Real = 1.0— length factor applied to each unit-tangent arrow vector; pass this directly to your quiver/arrow plotting call.
Returns
An ArrowData{D} with fields:
points—D × Nbase positions.vectors—D × Narrow vectors (unit tangent ×scale).speeds—N-vector of‖velocity‖at each arrow, for color-mapping.indices— column indices into the originalStreamlineData.pathsmatrix (nearest vertex to each arrow position).
Examples
# Vertex-based (legacy)
arrows = streamarrows(result; every=15, scale=0.05)
# Uniform arc-length spacing
arrows = streamarrows(result; spacing=0.3, scale=0.05)UniformStreamlines.streamlines — Function
streamlines(str::StreamlineData; kwargs...)
streamlines!(ax, str::StreamlineData; kwargs...)Plot evenly-spaced streamlines from precomputed StreamlineData.
streamlines creates a new figure; streamlines! adds to an existing axis or plot. Both work with Makie (via MakieExt) and Plots.jl (via PlotsExt).
Common keyword arguments
| Keyword | Default | Description |
|---|---|---|
with_arrows | false | Draw directional arrowheads along streamlines |
arrows_spacing | automatic | Arc-length spacing between arrows (uniform placement) |
arrows_every | nothing | Legacy: place an arrow every N vertices; overrides arrows_spacing |
Makie-specific keyword arguments
| Keyword | Default | Description |
|---|---|---|
color | :blue | A color, or a per-point Vector from colorize |
colormap | — | Colormap when color is numeric (e.g. :viridis, :plasma) |
colorrange | automatic | (min, max) for the color mapping |
linewidth | inherited | Streamline width |
markersize | inherited (2-D) | Arrowhead size. In 2-D this is in pixels; in 3-D it is in data units (default auto-scaled to ~2 % of domain diagonal) |
Plots.jl-specific keyword arguments
| Keyword | Default | Description |
|---|---|---|
line_z | — | Per-point color values from colorize |
markersize | 1.0 | Scale factor for arrowhead size |
color | :blue | Series color / colormap when using line_z |
Examples
using UniformStreamlines
xs = LinRange(-2, 2, 200)
ys = LinRange(-2, 2, 200)
str = evenstream(xs, ys, (x, y) -> -y, (x, y) -> x)
# Makie
using CairoMakie
streamlines(str; color=colorize(str, :norm), colormap=:viridis,
with_arrows=true)
# Plots.jl
using Plots
c = colorize(str, :norm)
streamlines(str; line_z=c, color=:viridis,
with_arrows=true)UniformStreamlines.trace! — Method
trace!(verts, pos, x, x0, u, stepsize, maxvert, lower, upper, sgn) -> IntIntegrate a single streamline from x0 into the pre-allocated buffer verts (D × maxvert) using midpoint (RK2) steps with unit-velocity normalization (each step advances exactly stepsize in arc-length, regardless of field magnitude). pos and x are D-length working vectors. Returns the number of columns written.