Zephyr Scientific Library (zscilib)
|
Functions | |
int | zsl_interp_lerp (zsl_real_t v0, zsl_real_t v1, zsl_real_t t, zsl_real_t *v) |
Calculates a number between two numbers using linear interpolation, where 't' is the interpolation factor between 0.0f and 1.0f. More... | |
int | zsl_interp_find_x (struct zsl_interp_xy xy[], size_t n, zsl_real_t x, int *idx) |
Uses bisection to search the zsl_interp_xy array for the closest array position to 'x', assigning the matching index value to the 'idx' pointer. The array must be monotonic, but can be either increasing or decreasing between xy[0] and xy[n]. More... | |
int | zsl_interp_nn (struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3, zsl_real_t x2, zsl_real_t *y2) |
Nearest neighbour (AKA 'piecewise constant') interpolation based on zsl_real_ts. More... | |
int | zsl_interp_nn_arr (struct zsl_interp_xy xy[], size_t n, zsl_real_t x, zsl_real_t *y) |
Nearest neighbour (AKA 'piecewise constant') interpolation based on an array of zsl_real_ts. More... | |
int | zsl_interp_lin_y (struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3, zsl_real_t x2, zsl_real_t *y2) |
Linear (AKA 'piecewise linear') interpolation for Y between two points, based on zsl_real_ts. More... | |
int | zsl_interp_lin_y_arr (struct zsl_interp_xy xy[], size_t n, zsl_real_t x, zsl_real_t *y) |
Linear (AKA 'piecewise linear') interpolation for Y between two points, based on zsl_real_ts. More... | |
int | zsl_interp_lin_x (struct zsl_interp_xy *xy1, struct zsl_interp_xy *xy3, zsl_real_t y2, zsl_real_t *x2) |
Linear (AKA 'piecewise linear') interpolation for X between two points, based on zsl_real_ts. More... | |
int | zsl_interp_cubic_calc (struct zsl_interp_xyc xyc[], size_t n, zsl_real_t yp1, zsl_real_t ypn) |
Calculates xyc[n].y2 for natural cubic spline interpolation, based on the assigned xyc[n].x and xyc[n].y values. More... | |
int | zsl_interp_cubic_arr (struct zsl_interp_xyc xyc[], size_t n, zsl_real_t x, zsl_real_t *y) |
Natural cubic spline interpolation between two points, based on zsl_real_ts. More... | |
Helper functions to interpolate between known values.
int zsl_interp_cubic_arr | ( | struct zsl_interp_xyc | xyc[], |
size_t | n, | ||
zsl_real_t | x, | ||
zsl_real_t * | y | ||
) |
Natural cubic spline interpolation between two points, based on zsl_real_ts.
xyc | The array of X,Y,Y2 values to use when interpolating (min four!). |
n | The number of elements in the X,Y,Y2 array. |
x | The X value to interpolate for (x >= xyc[1].x, <= xyc[n-3].x). |
y | Pointer to the placeholder for the interpolated Y value. |
int zsl_interp_cubic_calc | ( | struct zsl_interp_xyc | xyc[], |
size_t | n, | ||
zsl_real_t | yp1, | ||
zsl_real_t | ypn | ||
) |
Calculates xyc[n].y2 for natural cubic spline interpolation, based on the assigned xyc[n].x and xyc[n].y values.
xyc | The array of X,Y,Y2 values to use when interpolating (min four!). |
n | The number of elements in the X,Y,Y2 array. |
yp1 | 1st derivative at 1. Set to >= 1e30 for natural spline. |
ypn | 1st derivative at n'th point. Set to >= 1e30 for natural spline. |
NOTE: This function must be called BEFORE using zsl_interp_cubic_arr.
int zsl_interp_find_x | ( | struct zsl_interp_xy | xy[], |
size_t | n, | ||
zsl_real_t | x, | ||
int * | idx | ||
) |
Uses bisection to search the zsl_interp_xy array for the closest array position to 'x', assigning the matching index value to the 'idx' pointer. The array must be monotonic, but can be either increasing or decreasing between xy[0] and xy[n].
xy | The array of zsl_real_t-based X,Y values to search. |
n | The number of elements in the X,Y array. |
x | The x value to search for. |
idx | Pointer to the placeholder for the position of x in the X,Y array. |
Definition at line 33 of file interp.c.
Referenced by zsl_interp_lin_y_arr(), and zsl_interp_nn_arr().
int zsl_interp_lerp | ( | zsl_real_t | v0, |
zsl_real_t | v1, | ||
zsl_real_t | t, | ||
zsl_real_t * | v | ||
) |
Calculates a number between two numbers using linear interpolation, where 't' is the interpolation factor between 0.0f and 1.0f.
v0 | The lower value used when interpolating. |
v1 | The upper value used when interpolating. |
t | The interpolation factor between 0.0f and 1.0f. |
v | Pointer to the placeholder for the interpolated value. |
This can be used for alpha-blending or easing of motion, amongst other things.
For example, you can use zsl_interp_lerp to move an object between two points in 5% increments, creating a smooth animation that slows down as you approach the second point. For each 'step' between the two points you can calculate the new position as follows:
int zsl_interp_lin_x | ( | struct zsl_interp_xy * | xy1, |
struct zsl_interp_xy * | xy3, | ||
zsl_real_t | y2, | ||
zsl_real_t * | x2 | ||
) |
Linear (AKA 'piecewise linear') interpolation for X between two points, based on zsl_real_ts.
xy1 | The lower XY pair used when interpolating. |
xy3 | The upper XY pair used when interpolating. |
y2 | The Y value to interpolate for (>= y1 && <= y3). |
x2 | Pointer to the placeholder for the interpolated X value. |
int zsl_interp_lin_y | ( | struct zsl_interp_xy * | xy1, |
struct zsl_interp_xy * | xy3, | ||
zsl_real_t | x2, | ||
zsl_real_t * | y2 | ||
) |
Linear (AKA 'piecewise linear') interpolation for Y between two points, based on zsl_real_ts.
xy1 | The lower XY pair used when interpolating. |
xy3 | The upper XY pair used when interpolating. |
x2 | The X value to interpolate for (>= x1 && <= x3). |
y2 | Pointer to the placeholder for the interpolated Y value. |
Definition at line 155 of file interp.c.
Referenced by zsl_interp_lin_y_arr().
int zsl_interp_lin_y_arr | ( | struct zsl_interp_xy | xy[], |
size_t | n, | ||
zsl_real_t | x, | ||
zsl_real_t * | y | ||
) |
Linear (AKA 'piecewise linear') interpolation for Y between two points, based on zsl_real_ts.
xy | The array of XY pairs tp use when interpolating (min two!). |
n | The number of elements in the XY array. |
x | The X value to interpolate for (x >= xy[0].x, <= xy[n-1].x). |
y | Pointer to the placeholder for the interpolated Y value. |
int zsl_interp_nn | ( | struct zsl_interp_xy * | xy1, |
struct zsl_interp_xy * | xy3, | ||
zsl_real_t | x2, | ||
zsl_real_t * | y2 | ||
) |
Nearest neighbour (AKA 'piecewise constant') interpolation based on zsl_real_ts.
xy1 | The lower XY pair used when interpolating. |
xy3 | The upper XY pair used when interpolating. |
x2 | The X value to interpolate for (>= x1 && <= x3). |
y2 | Pointer to the placeholder for the interpolated Y value. |
Definition at line 100 of file interp.c.
Referenced by zsl_interp_nn_arr().
int zsl_interp_nn_arr | ( | struct zsl_interp_xy | xy[], |
size_t | n, | ||
zsl_real_t | x, | ||
zsl_real_t * | y | ||
) |
Nearest neighbour (AKA 'piecewise constant') interpolation based on an array of zsl_real_ts.
xy | The array of XY pairs tp use when interpolating (min two!). |
n | The number of elements in the XY array. |
x | The X value to interpolate for (x >= xy[0].x, <= xy[n-1].x). |
y | Pointer to the placeholder for the interpolated Y value. |