Skip to content

maths

get_angled

get_angled(vectors, angle, default=(0, 0, 1), keep_norm=False, twist=0.0, seed=None, eps=1e-06)

Return a vector making the given angle (radians) with each input vector. The direction around the cone is controlled by twist (angle in radians around the input direction). You can set twist='random' to sample a uniform angle in [0, 2*pi).

Parameters:

Name Type Description Default
vectors (array_like, shape(..., 3))

Input vectors.

required
angle float or array_like, broadcastable to vectors[..., 0]

Cone half-angle (radians) with respect to each input vector.

required
default (array_like, shape(3))

Fallback direction when input vector is zero.

(0, 0, 1)
keep_norm bool

If True, scale the result by ||vectors|| (zeros stay unit).

False
twist float or array_like or random

Rotation (radians) around the input direction (choose the azimuth on the cone). If 'random', sample uniform in [0, 2*pi).

0.0
seed int or None

RNG seed when twist='random'.

None
eps float

Tolerance for near-colinearity with z-axis.

1e-06

Returns:

Name Type Description
w (ndarray, shape(..., 3))

Output vectors.

get_axis

get_axis(v, null=[0, 0, 1])

Normalize a vector or an array of vectors.

The vector can be specified as a string naming an axis : 'x', '-z', ...

Arguments
- v (vector or array of vectors or str) : the vector to normalize
- null (vector=(0, 0, 1)) : value to set to null vectors

Returns:

Type Description
- normalized vector(s), vector norm(s)

get_perp

get_perp(vectors, default=(0, 0, 1), normalize=False)

Compute a perpendicular vector to each input vector.

Parameters:

Name Type Description Default
vectors array_like

Input vectors of shape (..., 3).

required
default tuple or array_like

Default perpendicular used when the vector is zero.

(0, 0, 1)

Returns:

Name Type Description
perp ndarray

Perpendicular vectors of shape (..., 3).

maprange

maprange(t, t0=0.0, t1=1.0, v0=0.0, v1=1.0, factor=1.0, back=1.70158, amplitude=1.0, period=0.3, mode='LINEAR', easing='AUTO', normalized=False)

Remap a value (or array) from a source range to a target range with easing.

If normalized=True, t is interpreted directly as a normalized parameter u ∈ [0, 1] and only the output mapping [0,1] → [v0, v1] is applied. Otherwise, a normalized parameter is computed as u = clip((t - t0) / (t1 - t0), 0, 1) before easing and remapping.

Supported easing modes

The mode selects the easing curve family (case-insensitive):

'LINEAR', 'CONSTANT', 'QUAD', 'CUBIC', 'QUART', 'QUINT', 'EXPO', 'SINE', 'CIRC', 'BACK', 'BOUNCE', 'ELASTIC', 'BEZIER', 'SMOOTH', 'SMOOTHER'

Easing direction

The easing variant controls the direction/shape inside the family:

'IN', 'OUT', 'IN_OUT', or 'AUTO'.

You may also pass the combined syntax "{MODE}.{EASING}" in the mode argument (e.g., "CIRC.IN"). In that case, the suffix sets the easing direction and takes precedence; the separate easing parameter is ignored.

Parameters:

Name Type Description Default
t float or array - like

Value(s) to remap. If normalized=True, t is already the normalized parameter u. Otherwise it is first mapped from [t0, t1] to [0, 1].

required
t0 float or array - like

Source range. Can broadcast against t.

0.0, 1.0
t1 float or array - like

Source range. Can broadcast against t.

0.0, 1.0
v0 float or array - like

Target range. Can be scalars or arrays; broadcasting applies.

0.0, 1.0
v1 float or array - like

Target range. Can be scalars or arrays; broadcasting applies.

0.0, 1.0
factor float

Generic intensity/shape factor used by some easing families.

1.0
back float

Overshoot parameter for 'BACK' easing.

1.70158
amplitude float

Amplitude parameter for 'ELASTIC' easing.

1.0
period float

Period parameter for 'ELASTIC' easing.

0.3
mode str

Easing family name, optionally with .IN, .OUT, or .IN_OUT suffix.

'LINEAR'
easing (IN, OUT, IN_OUT, AUTO)

Direction/variant. Ignored if mode already contains a suffix.

'IN','OUT','IN_OUT','AUTO'
normalized bool

If True, skip normalization of t (assume t is already u ∈ [0,1]).

False

Returns:

Type Description
ndarray or float

Remapped value(s): v0 + (v1 - v0) * eased(u). The shape is the broadcasted shape of the inputs.

Notes
  • Inputs are converted with np.asarray and broadcast per NumPy rules.
  • If t0 == t1 and normalized=False, the normalization step is ill-defined and will yield inf/nan; ensure the source range has non-zero extent.
  • The semantics of 'AUTO' are delegated to the underlying easing implementation (commonly selects a reasonable default for the family).

Examples:

Linear remap of a scalar from [0, 10] to [0, 1]:

y = maprange(7.5, t0=0.0, t1=10.0, v0=0.0, v1=1.0, mode='LINEAR')

Ease-in circular from [0, 1] to [0, 100], using combined syntax:

y = maprange(0.25, v0=0.0, v1=100.0, mode='CIRC.IN', normalized=True)

Vectorized easing-out cubic from [-1, +1] to [0, 1]:

import numpy as np
t = np.linspace(-1.0, 1.0, 256)
y = maprange(t, t0=-1.0, t1=1.0, v0=0.0, v1=1.0, mode='CUBIC', easing='OUT')

Elastic easing with custom amplitude/period:

u = np.linspace(0.0, 1.0, 200)
y = maprange(u, v0=0.0, v1=1.0, mode='ELASTIC', easing='IN_OUT',
             normalized=True, amplitude=1.2, period=0.25)

noise

noise(coords, t=None, scale=1.0, octaves=5, lacunarity=2.0, gain=0.5, normalize=True, period=None, algo='fBM', perlin=0, out_dim=1, **kwargs)

Global noise API.

Parameters:

Name Type Description Default
coords array - like

(N,) pour 1D, ou (N, dim) pour dim∈{1,2,3,4}.

required
t float = None

Supplementary dimension

None
scale float = 1.0

Échelle appliquée aux coordonnées (coords * scale).

1.0
octaves float

Nb d'octaves (peut être non entier) pour fBM / variantes Musgrave.

5
lacunarity float

Multiplicateur de fréquence par octave.

2.0
gain float

Décroissance d'amplitude (selon l'algo).

0.5
normalize bool

Normalisation (utilisée par fBM simple).

True
period int | tuple[int] | None

Période (tiling) en cellules (propagée par octave si applicable).

None
algo str

'perlin', 'fBM' (ou 'fbm'), 'multifractal' ('multi'), 'ridged' ('ridged_multifractal'), 'hybrid' ('hybrid_multifractal'), 'hetero' ('hetero_terrain').

'fBM'
perlin Perlin | int

Instance Perlin, ou seed (int). La dim est déduite de coords.

0
out_dim int

Number of dimensions in the result

1
**kwargs
  • dimension (float, défaut 1.0) : exposé pour les variantes Musgrave
  • offset (float) : utilisé par 'ridged', 'hybrid', 'hetero' (défauts adaptés)
{}

Returns:

Type Description
ndarray

Valeurs de bruit shape (N,) ou shape(N, out_dim)

set_spline2d_thickness

set_spline2d_thickness(points, thickness=0.1, mode=0, factor=1.0, cuts=(0.1, np.nan), inner_mode=None, inner_factor=None, inner_cuts=None, resolution=12, offset=0.0, cyclic=False, start_thickness=1, end_thickness=1)

Build a 2D stroke outline from the polyline with per-corner miters/fillets.

This method constructs a single polygonal outline from the current polyline by: (1) offsetting a copy to the "inner" side and resolving its corners, (2) offsetting a copy to the "outer" side and resolving its corners, then (3) reversing the outer side and concatenating both sides into one path. Corner geometry is produced by miter_corners; the effective corner radius is computed per vertex as radius = thickness * factor.

Parameters:

Name Type Description Default
thickness float or array-like of shape (n,)

Target stroke width per vertex. Scalars are broadcast to all vertices. The distance between the two resulting offset sides is thickness[i] at vertex i.

0.1
mode int or array-like of shape (n,)

Corner style for the outer side:

  • 0nothing corner is not changed
  • 1flat (bevel: straight segment between the two trimmed points)
  • 2round (fillet: arc sampled between the two trimmed points)
  • 3cut (cut the corner at distance and given angle)
0
factor float or array-like of shape (n,)

Per-corner effect factor.

1.0
cuts couple of floats or array-like of couples of floats

First value is the distance of the cut measured along the first segment. Second value is the angle (in radians) of the cut line. If second value is np.nan, the cut is perpendicular to the first segment.

(.1, np.nan)
inner_mode None, int or array-like of shape (n,)

Corner style for the inner side. If None, falls back to mode.

None
inner_factor float or array-like of shape (n,)

Same as factor for inner side.

None
inner_cuts float or couple of floats or array-like of such values

Same as cuts for inner line. If None, cuts is taken.

None
resolution int

Number of samples used for each rounded corner (when the corresponding mode is 0). Must be ≥ 2 to produce a visible arc.

12
offset float

Centerline bias in the range [-1, 1] that determines how the stroke is split between the two sides. Internally mapped to side offsets as:

  • -1[-thickness, 0] (all thickness on the inner/left side)
  • 0[-thickness/2, +thickness/2] (centered stroke)
  • +1[0, +thickness] (all thickness on the outer/right side)

Values are clipped to [-1, 1].

0.0
cyclic bool

If True, treat the polyline as closed; no end caps are applied and the outline is generated in closed form.

False
start_thickness float

Start-cap scaling when cyclic=False. A value of 0 collapses the start cap onto the first vertex; values > 0 scale the first outline points radially around the first vertex.

1
end_thickness float

End-cap scaling when cyclic=False. A value of 0 collapses the end cap onto the last vertex; values > 0 scale the last outline points radially around the last vertex.

1

Returns:

Name Type Description
pts ndarray of shape (m, 2)

The outline polygon: inner side (resolved with inner_mode) followed by the reversed outer side (resolved with mode). For cyclic=True, the outline is generated in closed form; otherwise, the path is open and not explicitly closed.

Notes
  • Side offsets are computed via perp_translated using the two per-vertex offset amounts derived from thickness and offset.
  • Corners on each side are replaced by either a bevel (mode==1) or a fillet arc (mode==0) computed by miter_corners with radius = thickness * factor.
  • When cyclic=False, start/end caps are optionally tapered using start_thickness and end_thickness.

Caution: If a local segment is too short for the requested trim/fillet, internal clamping ensures the trim does not exceed half the adjacent segment length.

Examples:

Centered round stroke:

outline = poly.set_thickness(
    thickness=0.12,
    offset=0.0,            # centered
    mode=0,                # round outer
    inner_mode=0,          # round inner
    resolution=16,
    cyclic=False
)

Asymmetric stroke with flat outer corners and rounded inner corners:

outline = poly.set_thickness(
    thickness=0.2,
    offset=+1,             # all thickness on outer/right side
    mode=1,                # flat outer
    inner_mode=0,          # round inner
    factor=0.8,
    resolution=12
)

Tapered open stroke (fade-in/out caps):

outline = poly.set_thickness(
    thickness=np.linspace(0.0, 0.15, len(poly.points)),
    mode=0,
    start_thickness=0.0,   # collapse start cap
    end_thickness=0.4      # shrink end cap
)

See also