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 |
required |
t0
|
float or array - like
|
Source range. Can broadcast against |
0.0, 1.0
|
t1
|
float or array - like
|
Source range. Can broadcast against |
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 |
1.70158
|
amplitude
|
float
|
Amplitude parameter for |
1.0
|
period
|
float
|
Period parameter for |
0.3
|
mode
|
str
|
Easing family name, optionally with |
'LINEAR'
|
easing
|
(IN, OUT, IN_OUT, AUTO)
|
Direction/variant. Ignored if |
'IN','OUT','IN_OUT','AUTO'
|
normalized
|
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
ndarray or float
|
Remapped value(s): |
Notes
- Inputs are converted with
np.asarray
and broadcast per NumPy rules. - If
t0 == t1
andnormalized=False
, the normalization step is ill-defined and will yieldinf
/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
|
|
{}
|
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 |
0.1
|
mode
|
int or array-like of shape (n,)
|
Corner style for the outer side:
|
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
|
(.1, np.nan)
|
inner_mode
|
None, int or array-like of shape (n,)
|
Corner style for the inner side. If |
None
|
inner_factor
|
float or array-like of shape (n,)
|
Same as |
None
|
inner_cuts
|
float or couple of floats or array-like of such values
|
Same as |
None
|
resolution
|
int
|
Number of samples used for each rounded corner (when the corresponding mode is |
12
|
offset
|
float
|
Centerline bias in the range
Values are clipped to |
0.0
|
cyclic
|
bool
|
If |
False
|
start_thickness
|
float
|
Start-cap scaling when |
1
|
end_thickness
|
float
|
End-cap scaling when |
1
|
Returns:
Name | Type | Description |
---|---|---|
pts |
ndarray of shape (m, 2)
|
The outline polygon: inner side (resolved with |
Notes
- Side offsets are computed via
perp_translated
using the two per-vertex offset amounts derived fromthickness
andoffset
. - Corners on each side are replaced by either a bevel (
mode==1
) or a fillet arc (mode==0
) computed bymiter_corners
withradius = thickness * factor
. - When
cyclic=False
, start/end caps are optionally tapered usingstart_thickness
andend_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
)