1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.0.1 (2010/10/01)
#include "Wm5MathematicsPCH.h"
#include "Wm5IntpAkima1.h"
#include "Wm5Math.h"
#include "Wm5Memory.h"
namespace Wm5
{
//----------------------------------------------------------------------------
template <typename Real>
IntpAkima1<Real>::IntpAkima1 (int quantity, Real* F)
{
// At least three data points are needed to construct the estimates of
// the boundary derivatives.
assertion(quantity >= 3 && F, "Invalid input\n");
mQuantity = quantity;
mF = F;
mPoly = new1<Polynomial>(quantity - 1 );
}
//----------------------------------------------------------------------------
template <typename Real>
IntpAkima1<Real>::~IntpAkima1 ()
{
delete1(mPoly);
}
//----------------------------------------------------------------------------
template <typename Real>
int IntpAkima1<Real>::GetQuantity () const
{
return mQuantity;
}
//----------------------------------------------------------------------------
template <typename Real>
const Real* IntpAkima1<Real>::GetF () const
{
return mF;
}
//----------------------------------------------------------------------------
template <typename Real>
const typename IntpAkima1<Real>::Polynomial*
IntpAkima1<Real>::GetPolynomials () const
{
return mPoly;
}
//----------------------------------------------------------------------------
template <typename Real>
const typename IntpAkima1<Real>::Polynomial&
IntpAkima1<Real>::GetPolynomial (int i) const
{
return mPoly[i];
}
//----------------------------------------------------------------------------
template <typename Real>
Real IntpAkima1<Real>::ComputeDerivative (Real* slope) const
{
if (slope[1] != slope[2])
{
if (slope[0] != slope[1])
{
if (slope[2] != slope[3])
{
Real ad0 = Math<Real>::FAbs(slope[3] - slope[2]);
Real ad1 = Math<Real>::FAbs(slope[0] - slope[1]);
return (ad0*slope[1] + ad1*slope[2])/(ad0+ad1);
}
else
{
return slope[2];
}
}
else
{
if (slope[2] != slope[3])
{
return slope[1];
}
else
{
return ((Real)0.5)*(slope[1] + slope[2]);
}
}
}
else
{
return slope[1];
}
}
//----------------------------------------------------------------------------
template <typename Real>
Real IntpAkima1<Real>::operator() (Real x) const
{
int index;
Real dx;
if (Lookup(x, index, dx))
{
return mPoly[index](dx);
}
return Math<Real>::MAX_REAL;
}
//----------------------------------------------------------------------------
template <typename Real>
Real IntpAkima1<Real>::operator() (int order, Real x) const
{
int index;
Real dx;
if (Lookup(x, index, dx))
{
return mPoly[index](order, dx);
}
return Math<Real>::MAX_REAL;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// IntpAkima1::Polynomial
//----------------------------------------------------------------------------
template <typename Real>
Real IntpAkima1<Real>::Polynomial::operator() (Real x) const
{
return mCoeff[0] + x*(mCoeff[1] + x*(mCoeff[2] + x*mCoeff[3]));
}
//----------------------------------------------------------------------------
template <typename Real>
Real IntpAkima1<Real>::Polynomial::operator() (int order, Real x) const
{
switch (order)
{
case 0:
return mCoeff[0] + x*(mCoeff[1] + x*(mCoeff[2] + x*mCoeff[3]));
case 1:
return mCoeff[1] + x*(((Real)2)*mCoeff[2] + x*((Real)3)*mCoeff[3]);
case 2:
return ((Real)2)*mCoeff[2] + x*((Real)6)*mCoeff[3];
case 3:
return ((Real)6)*mCoeff[3];
}
return (Real)0;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Explicit instantiation.
//----------------------------------------------------------------------------
template WM5_MATHEMATICS_ITEM
class IntpAkima1<float>;
template WM5_MATHEMATICS_ITEM
class IntpAkima1<double>;
//----------------------------------------------------------------------------
}
|