2.1.18.16 ocmath_renka_cline_interpolation
Description
This subroutine generates a two-dimensional surface interpolating
a set of scattered data points, using the method of Renka
and Cline.
Syntax
int ocmath_renka_cline_interpolation( int npts, double * x, double * y, double * f, ocmath_RenkaCline_Struct * comm )
Parameters
- npts
- [input] number of nodes and associated data values.
- npts should be larger than or equal to 3.
- x
- [input] array of length n containing the cartesian x coordinates of the nodes
- y
- [input] array of length n containing the cartesian y coordinates of the nodes
- f
- [input] array of length n containing the data values in one-to-one correspondence with the nodes.
- comm
- [output] the structure containing the result and the option of the interpolation
Return
Err_Intp_No_Error: No error occur;
Err_Intp_Mem_Fail: Fails to allocate memory;
Err_Intp_Invalid_Point: Not enough points or all points collinear
Err_Intp_Duplicate_Point: Duplicate points founded
Examples
EX1
#include <wks2mat.h>
void ocmath_renka_cline_interpolation_ex1()
{
double x[9] = { 0.,1.,1.,0.,.25,.5,.75,.5, 1. };
double y[9] = { 0.,0.,1.,1.,.5,.3,.5,.7 , 0.5};
double z[9] = { 0, 1, 2, 1, 0.5, 0.59, 1, 0.99, 1.25};
double px[5] = { .1,.3,.5,.7,.9 };
double py[5] = { .2,.4,.6,.8, .4 };
int n = 9;
ocmath_RenkaCline_Struct comm;
ocmath_renka_cline_interpolation(n, x, y, z,&comm);
int m = 5;
double pf[5];
ocmath_renka_cline_eval(&comm, m, px, py, pf);
for(int i=0; i<m; i++)
printf("%g\t%g\t%g\n\n", px[i], py[i], pf[i]);
ocmath_renka_cline_struct_free(&comm);
}
EX2
//assume there are x, y, z data in the first three columns of active worksheet
//this example will create a new matrix storing gridding data
#include <wks2mat.h>
#include <wksheet.h>
void ocmath_renka_cline_interpolation_ex2()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
out_str("found no active worksheet");
return;
}
Dataset dsX(wks, 0);
Dataset dsY(wks, 1);
Dataset dsZ(wks, 2);
int npts = dsX.GetSize();
vector vX = dsX;
vector vY = dsY;
vector vZ = dsZ;
ocmath_RenkaCline_Struct comm;
ocmath_renka_cline_interpolation(npts, vX, vY, vZ, &comm);
//set X and Y of the gridding
double dXMin, dXMax, dYMin, dYMax;
vX.GetMinMax(dXMin, dXMax);
vY.GetMinMax(dYMin, dYMax);
//perform random matrix conversion using Kriging algorithm
int nRows = 100;
int nCols = 50;
matrix mZ(nRows, nCols);
vector vEvalX(nRows * nCols);
vector vEvalY(nRows * nCols);
ocmath_mat_to_regular_xyz(NULL, nRows, nCols, dXMin, dXMax, dYMin, dYMax, vEvalX, vEvalY, NULL, true);
ocmath_renka_cline_eval(&comm, nRows * nCols, vEvalX, vEvalY, mZ);
ocmath_renka_cline_struct_free(&comm);
//create Matrix storing the result
MatrixLayer mResultLayer;
mResultLayer.Create();
Matrix matResult(mResultLayer);
matResult = mZ;
MatrixObject mo = mResultLayer.MatrixObjects(0);
mo.SetXY(dXMin, dYMin, dXMax, dYMax);//set X and Y range of Matrix
}
Remark
See Also
Header to Include
wks2mat.h
Reference
|