package OCADml

  1. Overview
  2. Docs

Cubic spline interpolation of 2d paths.

This is a port of a javascript implementation underlying a spline visualization tool by Timo Denk.

type boundary = [
  1. | `Quadratic
  2. | `NotAKnot
  3. | `Periodic
  4. | `Natural
]

Boundary condition for cubic spline fitting.

type coef = private {
  1. a : float;
  2. b : float;
  3. c : float;
  4. d : float;
}

Cubic spline coefficients

type t

Calculated coefficients along with the X ranges that they apply to. Abstracted to protect array access

Immutable access to fit results

val len : t -> int

len t

Length of the X range and coefficient arrays stored in t.

val xmins : t -> float list

xmins t

Minimum X values to which the coefficients at the same indices within t apply.

val xmaxs : t -> float list

xmaxs t

Maximum X values to which the coefficients at the same indices within t apply.

val coefs : t -> coef list

coefs t

Coefficients describing a cubic spline, as calculated by fit.

Index getters

val get_xmin : t -> int -> float option
val get_xmax : t -> int -> float option
val get_coef : t -> int -> coef option
val get_xmin_exn : t -> int -> float
val get_xmax_exn : t -> int -> float
val get_coef_exn : t -> int -> coef

Fitting

val fit : ?boundary:boundary -> V2.t list -> t

fit ?boundary ps

Calculate cubic spline coefficients with the boundary condition (defaults to `Natural) for the 2-dimensional control points ps.

Extrapolation

val extrapolate : t -> float -> float option

extrapolate t x

Calculate the corresponding dependent value (e.g. Some y) for the given independent value x using the cubic spline fit coefficient in t. If x does not fall within the range of the control values used to generate t, None is returned.

val extrapolate_path : t -> float list -> V2.t list

extrapolate_path t xs

Use t to extrapolate xs into a 2-dimensional cubic spline path.

val interpolate_path : fn:int -> t -> V2.t list

interpolate_path t n

Use t to interpolate 2-dimensional cubic spline path with n evently spaced points.

Utility

val coef_to_string : coef -> string

coef_to_string c

Show contents of c as a string.

OCaml

Innovation. Community. Security.