2 WARNING - Do not remove this header.
4 This code is a templated version of the 'magic-software' spherical
5 interpolation code by Dave Eberly. The original (un-hacked) code can be
6 obtained from here: http://www.magic-software.com/gr_appr.htm
7 This code is derived from linintp2.h/cpp and sphrintp.h/cpp.
9 Dave Eberly says that the conditions for use are:
11 * You may distribute the original source code to others at no charge.
13 * You may modify the original source code and distribute it to others at
14 no charge. The modified code must be documented to indicate that it is
15 not part of the original package.
17 * You may use this code for non-commercial purposes. You may also
18 incorporate this code into commercial packages. However, you may not
19 sell any of your source code which contains my original and/or modified
20 source code. In such a case, you need to factor out my code and freely
23 * The original code comes with absolutely no warranty and no guarantee is
24 made that the code is bug-free.
26 This does not seem incompatible with GPL - so this modified version
27 is hereby placed under GPL along with the rest of FlightGear.
35 #include <simgear/compiler.h>
41 SG_USING_NAMESPACE(std);
45 class SphereInterpolate
48 SphereInterpolate (int n, const double* x, const double* y,
49 const double* z, const unsigned int* f);
50 SphereInterpolate (int n, const sgVec2* p, const unsigned int* f);
52 ~SphereInterpolate ();
54 void GetSphericalCoords (const double x, const double y, const double z,
55 double& thetaAngle, double& phiAngle) const;
57 int Evaluate (const double x, const double y, const double z, EvaluateData& f) const;
58 int Evaluate (const double thetaAngle, const double phiAngle, EvaluateData& f) const;
61 // CodeWarrior doesn't know the differece between sgVec2 and
62 // sgVec3, so I commented this out for Mac builds. This change is
63 // related to a similar change in FGLocalWeatherDatabase module.
65 EvaluateData Evaluate(const sgVec2& p) const
68 Evaluate(p[1], p[0], retval);
74 EvaluateData Evaluate(const sgVec3& p) const
77 if (!Evaluate(p[1], p[0], retval))
79 cout << "Error during spherical interpolation. Point ("
80 << p[0] << "/" << p[1] << "/" << p[2] << ") was in no triangle\n";
81 retval.index[0] = 0; //fake something
84 retval.percentage[0] = 1.0;
85 retval.percentage[1] = 0.0;
86 retval.percentage[2] = 0.0;
96 mgcLinInterp2D* pInterp;