Shared

Curves

DigitalArt.CurvesModule
Curves

Parametric curve definitions and differential geometry utilities.

Provides standard curve definitions (circle, figure-eight, heart, etc.) and the mathematical tools needed to work with them: derivatives, curvature, arc-length tables, and arc-length resampling.

All curves are functions t -> SVector{2} mapping a real parameter to a 2D point.

DigitalArt.Curves.arclength_reparamMethod
arclength_reparam(f, t_start, t_end; resolution=1000) -> Function

Return a closure t(s) mapping arc length s to the curve parameter t reaching that arc length. Built once from a sampled arc-length table; reuse it instead of rebuilding the table per query. Extrapolates linearly.

DigitalArt.Curves.compute_arc_length_tableMethod
compute_arc_length_table(f, ts) -> (points, lengths)

Build a cumulative arc-length table for curve f sampled at parameter values ts.

Returns:

  • points: vector of SVector{2} curve points
  • lengths: cumulative arc lengths (same length as ts, starts at 0)
DigitalArt.Curves.compute_curve_normal_directionMethod
compute_curve_normal_direction(f, t) -> SVector{2}

Unit normal vector (rotated 90° CCW from tangent) to curve f at parameter t.

At a cusp or stationary point the tangent vanishes and the normal is undefined. Rather than returning NaN — which silently propagates into any position computed from it — this probes a short distance either side of t for a non-degenerate tangent, so the normal stays continuous with the surrounding curve. Falls back to (0, 1) only if the curve is degenerate throughout.

DigitalArt.Curves.curvatureMethod
curvature(f, t) -> Float64

Signed curvature magnitude κ of curve f at parameter t.

Uses the 2D formula κ = |v × a| / |v|³ where v = f'(t), a = f''(t). Returns 0 at inflection points where the denominator vanishes.

DigitalArt.Curves.heartMethod
heart(t) -> SVector{2}

Heart curve. Parameter range: [0, 2π]. Scale by a small factor (e.g. 0.1) when composing with other curves to normalise size.

DigitalArt.Curves.ovalMethod
oval(t; a=2, b=1) -> SVector{2}

Axis-aligned ellipse with semi-axes a (horizontal) and b (vertical). Parameter range: [0, 2π].

DigitalArt.Curves.resample_by_arclengthMethod
resample_by_arclength(f, t_start, t_end, n_samples; resolution=1000)
    -> (points, ts_sampled, total_length)

Return n_samples points equally spaced by arc length along curve f over [t_start, t_end].

Returns:

  • points: equally arc-length-spaced curve points
  • ts_sampled: corresponding parameter values
  • total_length: total arc length of the curve
DigitalArt.Curves.spiralMethod
spiral(t) -> SVector{2}

Archimedean spiral. Parameter range determines number of turns.

DigitalArt.Curves.tangent_angleMethod
tangent_angle(f, t) -> Float64

Angle (radians) of the tangent vector to curve f at parameter t, measured from the positive x-axis.

DigitalArt.Curves.total_arc_lengthMethod
total_arc_length(f, t_start, t_end; resolution=1000) -> Float64

Compute the total arc length of curve f over [t_start, t_end].