public class GridAxis extends Object implements Serializable
This class is intended to be used for interpolating inside grids.
It works on any sorted data without duplication and size at least
n
where n
is the number of points required for
interpolation (i.e. 2 for linear interpolation, 3 for quadratic...)
The method uses linear interpolation to select the nodes indices. It should be O(1) for sufficiently regular data, therefore much faster than bisection. It also features caching, which improves speed when interpolating several points in raw in the close locations, i.e. when successive calls have a high probability to return the same interpolation nodes. This occurs for example when scanning with small steps a loose grid. The method also works on non-regular grids, but may be slower in this case.
This class is thread-safe.
Constructor and Description |
---|
GridAxis(double[] grid,
int n)
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
getN()
Get the number of points required for interpolation.
|
int |
interpolationIndex(double t)
Get the index of the first interpolation node for some coordinate along the grid.
|
double |
node(int index)
Get the interpolation node at specified index.
|
int |
size()
Get the number of points of the grid.
|
public GridAxis(double[] grid, int n) throws MathIllegalArgumentException
grid
- coordinates of the interpolation points, sorted in increasing ordern
- number of points required for interpolation, i.e. 2 for linear, 3
for quadratic...MathIllegalArgumentException
- if grid size is smaller than n
or if the grid is not sorted in strict increasing orderpublic int size()
public int getN()
public double node(int index)
index
- node indexpublic int interpolationIndex(double t)
The index return is the one for the lowest interpolation node suitable for
t
. This means that if i
is returned the nodes to use for
interpolation at coordinate t
are at indices i
, i+1
,
..., i+n-1
, where n
is the number of points required for
interpolation passed at construction.
The index is selected in order to have the subset of nodes from i
to
i+n-1
as balanced as possible around t
:
t
is inside the grid and sufficiently far from the endpoints
n
is even, the returned nodes will be perfectly balanced:
there will be n/2
nodes smaller than t
and n/2
nodes larger than t
n
is odd, the returned nodes will be slightly unbalanced by
one point: there will be (n+1)/2
nodes smaller than t
and (n-1)/2
nodes larger than t
t
is inside the grid and close to endpoints, the returned nodes
will be unbalanced: there will be less nodes on the endpoints side and
more nodes on the interior side
t
is outside of the grid, the returned nodes will completely
off balance: all nodes will be on the same side with respect to t
It is not an error to call this method with t
outside of the grid,
it simply implies that the interpolation will become an extrapolation and accuracy
will decrease as t
goes farther from the grid points. This is intended so
interpolation does not fail near the end of the grid.
t
- coordinate of the point to interpolatei
such node(i)
, node(i+1)
,
... node(i+n-1)
can be used for interpolating a value at
coordinate t
Copyright © 2016–2020 Hipparchus.org. All rights reserved.