Class GridAxis
- java.lang.Object
-
- org.hipparchus.analysis.interpolation.GridAxis
-
- All Implemented Interfaces:
Serializable
public class GridAxis extends Object implements Serializable
Helper for finding interpolation nodes along one axis of grid data.This class is intended to be used for interpolating inside grids. It works on any sorted data without duplication and size at least
n
wheren
is the number of points required for interpolation (i.e. 2 for linear interpolation, 3 for quadratic...)This class is thread-safe.
- Since:
- 1.4
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GridAxis(double[] grid, int n)
Simple constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
GridAxis
public GridAxis(double[] grid, int n) throws MathIllegalArgumentException
Simple constructor.- Parameters:
grid
- coordinates of the interpolation points, sorted in increasing ordern
- number of points required for interpolation, i.e. 2 for linear, 3 for quadratic...- Throws:
MathIllegalArgumentException
- if grid size is smaller thann
or if the grid is not sorted in strict increasing order
-
-
Method Detail
-
size
public int size()
Get the number of points of the grid.- Returns:
- number of points of the grid
-
getN
public int getN()
Get the number of points required for interpolation.- Returns:
- number of points required for interpolation
-
node
public double node(int index)
Get the interpolation node at specified index.- Parameters:
index
- node index- Returns:
- coordinate of the node at specified index
-
interpolationIndex
public int interpolationIndex(double t)
Get the index of the first interpolation node for some coordinate along the grid.The index return is the one for the lowest interpolation node suitable for
t
. This means that ifi
is returned the nodes to use for interpolation at coordinatet
are at indicesi
,i+1
, ...,i+n-1
, wheren
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
toi+n-1
as balanced as possible aroundt
:-
if
t
is inside the grid and sufficiently far from the endpoints-
if
n
is even, the returned nodes will be perfectly balanced: there will ben/2
nodes smaller thant
andn/2
nodes larger thant
-
if
n
is odd, the returned nodes will be slightly unbalanced by one point: there will be(n+1)/2
nodes smaller thant
and(n-1)/2
nodes larger thant
-
if
-
if
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 -
if
t
is outside of the grid, the returned nodes will completely off balance: all nodes will be on the same side with respect tot
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 ast
goes farther from the grid points. This is intended so interpolation does not fail near the end of the grid.- Parameters:
t
- coordinate of the point to interpolate- Returns:
- index
i
suchnode(i)
,node(i+1)
, ...node(i+n-1)
can be used for interpolating a value at coordinatet
- Since:
- 1.4
-
if
-
-