# Module OgamlUtils.Interpolator

Interpolation between multiple values This module defines interpolators between two values.

An interpolator between value v0 and v1 is a function f such that f(0) = v0, f(1) = v1.

### Accessors and modifiers

Those functions provide a way to modify the behaviour of interpolators.

Unless otherwise specified, the modifiers applied to an interpolator are kept by all subsequent operations. This means that, for example, passing a time-based interpolator to `map`

will return a new time-based interpolator.

`get ip t`

returns the value of the interpolator `ip`

at time `t`

in [0;1]
`current ip`

returns the current value of a time-based interpolator (see function start).If

`ip`

is not time-based then the result is `ip(0)`

.
`start ip t dt`

returns a new time-based interpolator `tip`

such that :`current tip`

= `ip(0)`

at time `t`

`current tip`

= `ip(1)`

at time `t + dt`

`t`

and `dt`

are given in seconds. `t = Unix.gettimeofday()`

means that `tip`

starts immediately.If

`dt = 0`

then `current`

will always return `ip(0)`

The result of

`get`

on the `tip`

is left unchanged.
`repeat ip`

returns a repeating interpolator `lip`

from `ip`

such that`lip(x)`

= `ip(x)`

for `x`

in [0;1] and `lip`

is 1-periodic.
`loop ip`

returns a repeating interpolator `lip`

from `ip`

such that :`lip(x)`

= `ip(x)`

for `x`

in [0;1] `lip(x)`

= `ip(2-x)`

for `x`

in [1;2]`lip(x)`

is 2-periodic
### Constructors

Those functions provide a way to construct various (and even user-defined) interpolators.

Unless otherwise specified, parameters are clamped to [0;1], that is ip(x) for x < 0 equals ip(0) and ip(x) for x > 1 equals ip(1)

Most constructors require a list of points of the form `(dt, v)`

such that the created interpolator will take the value `v`

at time `dt`

.

The `cst_*`

variants create constant-speed interpolators so the `dt`

parameter is not required.

`custom f start stop`

returns a custom interpolator `ip`

that coincides with the function `f`

such that `ip(0) = f(start)`

, `ip(1) = f(stop)`

.
`copy f`

returns a custom interpolator that coincides with the function `f`

everywhere
`linear start steps endt`

creates a linear interpolator going from `start`

to `endt`

passing through each point`(dt, pos)`

of `steps`

at time `dt < 1.0`

`cst_linear start steps endt`

creates a linear interpolator going from `start`

to `endt`

passing through each point of `steps`

at constant speed
`cubic (start, sm) steps (endt, em)`

creates a cubic spline interpolator going from `start`

with tangent `sm`

to `endt`

with tangent `em`

passing through each point `(dt, pos)`

of `steps`

at time `dt < 1.0`

`cubic (start, sm) steps (endt, em)`

creates a cubic spline interpolator going from `start`

with tangent `sm`

to `endt`

with tangent `em`

passing through each point of `steps`

at constant speed
### Composition

`compose ip1 ip2`

returns a new interpolator that takes the values of `ip2`

but using the values of `ip1`

as parameterThe new interpolator will have the modifiers of

`ip1`

`map ip f`

returns a new interpolator that takes the value of `ip`

and passes it to `f`

.
`map_right`

is an alias for `map`

`map_left f ip`

returns a function `g`

such that `g(x) = ip(f(x))`

The new interpolator will not have any modifiers.

The new interpolator will not have any modifiers.

The new interpolator will not have any modifiers.

The new interpolator will not have any modifiers.