planar_intp Class Template Reference

Interpolate among two independent variables with planes. More...

#include <planar_intp.h>


Detailed Description

template<class vec_t, class mat_t>
class planar_intp< vec_t, mat_t >

Interpolate among two independent variables with planes.

This is an analog of 1-d linear interpolation for two dimensions. For a set of data ${x_i,y_i,f_{j,i}}$, the values of $f_j$ are predicted given a value of x and y. In contrast to twod_intp, the data need not be presented in a grid. This is done by finding the plane that goes through three closest points in the data set. Distances are determined with

\[ d_{ij} = \sqrt{\left(\frac{x_i-x_j}{\Delta x}\right)^2 + \left(\frac{y_i-y_j}{\Delta y}\right)^2} \]

where $ \Delta x = x_{\mathrm{max}}-x_{\mathrm{min}} $ and $ \Delta y = y_{\mathrm{max}}-y_{\mathrm{min}} $ .

This procedure will fail if the three closest points are co-linear, and interp() will then call O2SCL_ERR() and return zero.

There is no caching so the numeric values of the data may be freely changed between calls to interp().

The vector and matrix types can be any types which have suitably defined functions operator[].

For example, with 10 points in the x-y plane with $ -1<x<1 $ and $ -1<y<1 $, the planes are demarcated according to

in_planar_intp.png

in_planar_intp.png

where each polygonal region represents the set of all points in the domain which will be mapped to the same plane to approximate the function.

Idea for future:
Rewrite so that it never fails unless all the points in the data set lie on a line. This would probably demand sorting all of the points by distance from desired location.
Idea for future:
Instead of comparing den with zero, add the option of comparing it with a small number.

Definition at line 77 of file planar_intp.h.


Public Member Functions

int set_data (size_t n_points, vec_t &x, vec_t &y, size_t n_dat, mat_t &dat)
 Initialize the data for the planar interpolation.
int interp (double x, double y, vec_t &ip)
 Perform the planar interpolation.
int interp (double x, double y, vec_t &ip, size_t &i1, double &x1, double &y1, size_t &i2, double &x2, double &y2, size_t &i3, double &x3, double &y3)
 Planar interpolation returning the closest points.

Protected Member Functions

int swap (size_t &i1, double &c1, size_t &i2, double &c2)
 Swap points 1 and 2.

Protected Attributes

size_t np
 The number of points.
size_t nd
 The number of functions.
vec_t * ux
 The x-values.
vec_t * uy
 The y-values.
mat_t * udat
 The data.
bool data_set
 True if the data has been specified.

Member Function Documentation

int interp ( double  x,
double  y,
vec_t &  ip,
size_t &  i1,
double &  x1,
double &  y1,
size_t &  i2,
double &  x2,
double &  y2,
size_t &  i3,
double &  x3,
double &  y3 
) [inline]

Planar interpolation returning the closest points.

This function interpolates x and y into the data returning ip. It also returns the three closest x- and y-values used for computing the plane.

It is assumed that ip is properly allocated beforehand.

Put in initial points

Sort initial points

Definition at line 121 of file planar_intp.h.

int interp ( double  x,
double  y,
vec_t &  ip 
) [inline]

Perform the planar interpolation.

It is assumed that ip is properly allocated beforehand.

Definition at line 106 of file planar_intp.h.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page