26 template<
class G>
void 27 compute(
double a,
double f, mwSize
m,
const double* latlong,
28 double* geodesic,
double* aux) {
29 const double* lat1 = latlong;
30 const double* lon1 = latlong +
m;
31 const double* lat2 = latlong + 2*
m;
32 const double* lon2 = latlong + 3*
m;
33 double* azi1 = geodesic;
34 double* azi2 = geodesic +
m;
35 double* s12 = geodesic + 2*
m;
50 for (mwIndex
i = 0;
i <
m; ++
i) {
51 if (
abs(lat1[
i]) <= 90 && lon1[i] >= -540 && lon1[i] < 540 &&
52 abs(lat2[i]) <= 90 && lon2[i] >= -540 && lon2[i] < 540) {
54 a12[
i] = g.Inverse(lat1[i], lon1[i], lat2[i], lon2[i],
55 s12[i], azi1[i], azi2[i],
56 m12[i], M12[i], M21[i], S12[i]);
58 g.Inverse(lat1[i], lon1[i], lat2[i], lon2[i],
59 s12[i], azi1[i], azi2[i]);
65 int nrhs,
const mxArray* prhs[] ) {
68 mexErrMsgTxt(
"One input argument required.");
70 mexErrMsgTxt(
"More than three input arguments specified.");
72 mexErrMsgTxt(
"Must specify flattening with the equatorial radius.");
74 mexErrMsgTxt(
"More than two output arguments specified.");
76 if (!( mxIsDouble(prhs[0]) && !mxIsComplex(prhs[0]) ))
77 mexErrMsgTxt(
"latlong coordinates are not of type double.");
79 if (mxGetN(prhs[0]) != 4)
80 mexErrMsgTxt(
"latlong coordinates must be M x 4 matrix.");
82 double a = Constants::WGS84_a<double>(),
f = Constants::WGS84_f<double>();
84 if (!( mxIsDouble(prhs[1]) && !mxIsComplex(prhs[1]) &&
85 mxGetNumberOfElements(prhs[1]) == 1 ))
86 mexErrMsgTxt(
"Equatorial radius is not a real scalar.");
87 a = mxGetScalar(prhs[1]);
88 if (!( mxIsDouble(prhs[2]) && !mxIsComplex(prhs[2]) &&
89 mxGetNumberOfElements(prhs[2]) == 1 ))
90 mexErrMsgTxt(
"Flattening is not a real scalar.");
91 f = mxGetScalar(prhs[2]);
94 mwSize
m = mxGetM(prhs[0]);
96 const double* latlong = mxGetPr(prhs[0]);
98 double* geodesic = mxGetPr(plhs[0] = mxCreateDoubleMatrix(m, 3, mxREAL));
99 std::fill(geodesic, geodesic + 3*m, Math::NaN<double>());
102 nlhs == 2 ? mxGetPr(plhs[1] = mxCreateDoubleMatrix(m, 5, mxREAL)) :
105 std::fill(aux, aux + 5*m, Math::NaN<double>());
109 compute<Geodesic>(
a,
f,
m, latlong, geodesic, aux);
111 compute<GeodesicExact>(
a,
f,
m, latlong, geodesic, aux);
113 catch (
const std::exception&
e) {
114 mexErrMsgTxt(e.what());
JacobiRotation< float > G
void g(const string &key, int i)
Header for GeographicLib::Geodesic class.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Header for GeographicLib::GeodesicExact class.
void compute(double a, double f, mwSize m, const double *latlong, double *geodesic, double *aux)