ocmath_3d_interpolate

 

Description

This function interpolates an input scattered data points at given 3d xyz coordinates, with the modified Shepard method.

Syntax

int ocmath_3d_interpolate( const double * pX, const double * pY, const double * pZ, double * pQ, UINT nSize, const double * pSrcX, const double * pSrcY, const double * pSrcZ, const double * pSrcF, UINT nSrcSize )

Parameters

pX
[input] pointer to X coordinate to be evaluated. size is nSize
pY
[input] pointer to Y coordinate to be evaluated. size is nSize
pZ
[input] pointer to Z coordinate to be evaluated. size is nSize
pQ
[output] pointer to the interpolation values at evaluation points. size is nSize
nSize
[input] size of evaluation points, nSize > 0
pSrcX
[input] pointer to the X value of original scattered data points, size is nSrcSize.
pSrcY
[input] pointer to the Y value of original scattered data points. size is nSrcSize.
pSrcZ
[input] pointer to the Z value of original scattered data points. size is nSrcSize.
pSrcF
[input] pointer to the F value of original scattered data points. size is nSrcSize.
nSrcSize
[input] size of original scattered data points, nSrcSize ≥ 10.

Return

Return 0 if succeed, or a non-zero Nag error codes:

NE_INT = 90: nSrcSize must be not less than 10. nSize must be larger than 1

NE_DATA_COPLANAR = 2083: All nodes are coplanar. There is no unique solution

NE_DUPLICATE_NODE = 2084: There are duplicate nodes in the dataset. The interpolant can not be derived.

NE_BAD_POINT = 2085: At least one evaluation points lies outside the region of definition of the interpolant.

Examples

EX1

//Before running, make sure a worksheet is active in current project
void ocmath_3d_interpolate_ex1(int nSize)
{
    Worksheet wks = Project.ActiveLayer();
    wks.SetSize(-1,4);
    DataRange drIn;
    drIn.Add("Range1", wks, 0, 0, -1, 0);
    drIn.Add("Range2", wks, 0, 1, -1, 1);
    drIn.Add("Range3", wks, 0, 2, -1, 2);
    drIn.Add("Range4", wks, 0, 3, -1, 3);
    
    vector vSrcX, vSrcY, vSrcZ, vSrcF;
    drIn.GetData(&vSrcX, 0);
    drIn.GetData(&vSrcY, 1);
    drIn.GetData(&vSrcZ, 2);
    drIn.GetData(&vSrcF, 3);
    
    int nSrcSize = vSrcX.GetSize();
    double dmin,dmax;
    vector vx,vy,vz,vf;
    
    vSrcX.GetMinMax(dmin,dmax);
    vx.Data(dmin, dmax, (dmax-dmin)/(nSize-1));
    
    vSrcY.GetMinMax(dmin,dmax);
    vy.Data(dmin, dmax, (dmax-dmin)/(nSize-1));
    
    vSrcZ.GetMinMax(dmin,dmax);
    vz.Data(dmin, dmax, (dmax-dmin)/(nSize-1));
    
    vf.SetSize(nSize);

    int nRet = ocmath_3d_interpolate(vx, vy, vz, vf, nSize, vSrcX, vSrcY, vSrcZ,vSrcF, nSrcSize);
     if (nRet != OE_NOERROR)
    {
        printf("Error occurs when calling ocmath function!\n");
        return
    }
    Worksheet    wksResult;
    wksResult.Create("InterResult");
    while(wksResult.Columns())
        wksResult.DeleteCol(0);
    for(int n=0; n < 4; n++)
        wksResult.AddCol();
    DataRange drOut;
    drOut.Add("X", wksResult, 0, 0, -1, 0);
    drOut.Add("X", wksResult, 0, 1, -1, 1);
    drOut.Add("X", wksResult, 0, 2, -1, 2);
    drOut.Add("X", wksResult, 0, 3, -1, 3);
    drOut.SetData(vx, false, 0);
    drOut.SetData(vy, false, 1);
    drOut.SetData(vz, false, 2);
    drOut.SetData(vf, false, 3);        
}

Remark

This function interpolates the input data exactly and has quadratic accuracy.

The time taken will depend in general on the distribution of the data points.

At worst, O(nSrcSize*(nSrcSize+nSize)) time will be required.

See Also

ocmath_2d_interpolate, ocmath_interpolate

header to Include

origin.h

Reference

nag_3d_shep_interp(e01tgc), nag_3d_shep_eval(e01thc)