35 # pragma warning (disable: 4701 4127) 43 : maxit2_(maxit1_ +
Math::digits() + 10)
54 , tolb_(tol0_ * tol2_)
55 , xthresh_(1000 * tol2_)
60 , _ep2(_e2 /
Math::sq(_f1))
83 , _etol2(
real(0.1) * tol2_ /
107 ar = 2 * (cosx - sinx) * (cosx + sinx),
108 y0 = n & 1 ? *--
c : 0, y1 = 0;
113 y1 = ar * y0 - y1 + *--
c;
114 y0 = ar * y1 - y0 + *--
c;
116 return cosx * (y0 - y1);
120 unsigned caps)
const {
125 bool arcmode,
real s12_a12,
135 GenPosition(arcmode, s12_a12, outmask,
136 lat2, lon2, azi2, s12, m12, M12, M21, S12);
141 bool arcmode,
real s12_a12,
142 unsigned caps)
const {
150 caps, arcmode, s12_a12);
155 unsigned caps)
const {
161 unsigned caps)
const {
167 unsigned outmask,
real& s12,
177 int lonsign = lon12 >= 0 ? 1 : -1;
195 int swapp =
abs(lat1) <
abs(lat2) ? -1 : 1;
201 int latsign = lat1 < 0 ? 1 : -1;
216 real sbet1, cbet1, sbet2, cbet2, s12x, m12x;
238 if (cbet1 < -sbet1) {
240 sbet2 = sbet2 < 0 ? sbet1 : -sbet1;
242 if (
abs(sbet2) == -sbet1)
254 bool meridian = lat1 == -90 || slam12 == 0;
261 calp1 = clam12; salp1 = slam12;
262 calp2 = 1; salp2 = 0;
266 ssig1 = sbet1, csig1 = calp1 * cbet1,
267 ssig2 = sbet2, csig2 = calp2 * cbet2;
270 sig12 =
atan2(
max(
real(0), csig1 * ssig2 - ssig1 * csig2),
271 csig1 * csig2 + ssig1 * ssig2);
274 Lengths(E, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
276 s12x, m12x, dummy, M12, M21);
285 if (sig12 < 1 || m12x >= 0) {
287 if (sig12 < 3 *
tiny_)
288 sig12 = m12x = s12x = 0;
298 real omg12 = 0, somg12 = 2, comg12 = 0;
301 (_f <= 0 || lon12s >=
_f * 180)) {
304 calp1 = calp2 = 0; salp1 = salp2 = 1;
306 sig12 = omg12 = lam12 /
_f1;
307 m12x =
_b *
sin(sig12);
309 M12 = M21 =
cos(sig12);
312 }
else if (!meridian) {
319 sig12 =
InverseStart(E, sbet1, cbet1, dn1, sbet2, cbet2, dn2,
320 lam12, slam12, clam12,
321 salp1, calp1, salp2, calp2, dnm);
325 s12x = sig12 *
_b * dnm;
328 M12 = M21 =
cos(sig12 / dnm);
330 omg12 = lam12 / (
_f1 * dnm);
346 real ssig1 = 0, csig1 = 0, ssig2 = 0, csig2 = 0, domg12 = 0;
350 for (
bool tripn =
false, tripb =
false;
375 real v =
Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1,
377 salp2, calp2, sig12, ssig1, csig1, ssig2, csig2,
378 E, domg12, numit <
maxit1_, dv);
380 if (tripb || !(
abs(v) >= (tripn ? 8 : 1) *
tol0_))
break;
382 if (v > 0 && (numit >
maxit1_ || calp1/salp1 > calp1b/salp1b))
383 { salp1b = salp1; calp1b = calp1; }
384 else if (v < 0 && (numit >
maxit1_ || calp1/salp1 < calp1a/salp1a))
385 { salp1a = salp1; calp1a = calp1; }
386 if (numit < maxit1_ && dv > 0) {
390 sdalp1 =
sin(dalp1), cdalp1 =
cos(dalp1),
391 nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
393 calp1 = calp1 * cdalp1 - salp1 * sdalp1;
411 salp1 = (salp1a + salp1b)/2;
412 calp1 = (calp1a + calp1b)/2;
415 tripb = (
abs(salp1a - salp1) + (calp1a - calp1) <
tolb_ ||
416 abs(salp1 - salp1b) + (calp1 - calp1b) <
tolb_);
420 Lengths(E, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
421 cbet1, cbet2, outmask, s12x, m12x, dummy, M12, M21);
426 if (outmask &
AREA) {
428 real sdomg12 =
sin(domg12), cdomg12 =
cos(domg12);
429 somg12 = slam12 * cdomg12 - clam12 * sdomg12;
430 comg12 = clam12 * cdomg12 + slam12 * sdomg12;
441 if (outmask &
AREA) {
444 salp0 = salp1 * cbet1,
447 if (calp0 != 0 && salp0 != 0) {
450 ssig1 = sbet1, csig1 = calp1 * cbet1,
451 ssig2 = sbet2, csig2 = calp2 * cbet2,
453 eps = k2 / (2 * (1 +
sqrt(1 + k2)) + k2),
463 S12 = A4 * (B42 - B41);
470 somg12 =
sin(omg12); comg12 =
cos(omg12);
476 comg12 > -
real(0.7071) &&
477 sbet2 - sbet1 <
real(1.75)) {
481 real domg12 = 1 + comg12, dbet1 = 1 + cbet1, dbet2 = 1 + cbet2;
482 alp12 = 2 *
atan2( somg12 * ( sbet1 * dbet2 + sbet2 * dbet1 ),
483 domg12 * ( sbet1 * sbet2 + dbet1 * dbet2 ) );
487 salp12 = salp2 * calp1 - calp2 * salp1,
488 calp12 = calp2 * calp1 + salp2 * salp1;
493 if (salp12 == 0 && calp12 < 0) {
494 salp12 =
tiny_ * calp1;
497 alp12 =
atan2(salp12, calp12);
500 S12 *= swapp * lonsign * latsign;
513 salp1 *= swapp * lonsign; calp1 *= swapp * latsign;
514 salp2 *= swapp * lonsign; calp2 *= swapp * latsign;
527 real salp1, calp1, salp2, calp2,
529 outmask, s12, salp1, calp1, salp2, calp2,
540 unsigned caps)
const {
541 real t, salp1, calp1, salp2, calp2,
544 0u, t, salp1, calp1, salp2, calp2,
557 real cbet1,
real cbet2,
unsigned outmask,
574 (sig12 + (E.
deltaE(ssig2, csig2, dn2) - E.
deltaE(ssig1, csig1, dn1)));
579 (sig12 + (E.
deltaD(ssig2, csig2, dn2) - E.
deltaD(ssig1, csig1, dn1)));
585 m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) -
589 real csig12 = csig1 * csig2 + ssig1 * ssig2;
590 real t =
_ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
591 M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
592 M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
605 if ( !(
q == 0 && r <= 0) ) {
614 disc = S * (S + 2 *
r3);
621 T3 += T3 < 0 ? -
sqrt(disc) :
sqrt(disc);
625 u += T + (T != 0 ? r2 /
T : 0);
631 u += 2 * r *
cos(ang / 3);
636 uv = u < 0 ?
q / (v - u) : u + v,
637 w = (uv -
q) / (2 *
v);
664 sbet12 = sbet2 * cbet1 - cbet2 * sbet1,
665 cbet12 = cbet2 * cbet1 + sbet2 * sbet1;
666 #if defined(__GNUC__) && __GNUC__ == 4 && \ 667 (__GNUC_MINOR__ < 6 || defined(__MINGW32__)) 681 real sbet12a = sbet2 * cbet1 + cbet2 * sbet1;
683 bool shortline = cbet12 >= 0 && sbet12 <
real(0.5) &&
684 cbet2 * lam12 <
real(0.5);
687 real sbetm2 =
Math::sq(sbet1 + sbet2);
690 sbetm2 /= sbetm2 +
Math::sq(cbet1 + cbet2);
692 real omg12 = lam12 / (
_f1 * dnm);
693 somg12 =
sin(omg12); comg12 =
cos(omg12);
695 somg12 = slam12; comg12 = clam12;
698 salp1 = cbet2 * somg12;
699 calp1 = comg12 >= 0 ?
700 sbet12 + cbet2 * sbet1 *
Math::sq(somg12) / (1 + comg12) :
701 sbet12a - cbet2 * sbet1 *
Math::sq(somg12) / (1 - comg12);
705 csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
707 if (shortline && ssig12 <
_etol2) {
709 salp2 = cbet1 * somg12;
710 calp2 = sbet12 - cbet1 * sbet2 *
711 (comg12 >= 0 ?
Math::sq(somg12) / (1 + comg12) : 1 - comg12);
714 sig12 =
atan2(ssig12, csig12);
722 real
y, lamscale, betscale;
727 real lam12x =
atan2(-slam12, -clam12);
733 lamscale =
_e2/
_f1 * cbet1 * 2 * E.
H();
735 betscale = lamscale * cbet1;
737 x = lam12x / lamscale;
738 y = sbet12a / betscale;
742 cbet12a = cbet2 * cbet1 - sbet2 * sbet1,
743 bet12a =
atan2(sbet12a, cbet12a);
744 real m12b, m0,
dummy;
748 sbet1, -cbet1, dn1, sbet2, cbet2, dn2,
750 x = -1 + m12b / (cbet1 * cbet2 * m0 *
Math::pi());
751 betscale = x < -
real(0.01) ? sbet12a /
x :
753 lamscale = betscale / cbet1;
754 y = lam12x / lamscale;
803 omg12a = lamscale * (
_f >= 0 ? -x * k/(1 + k) : -y * (1 + k)/k );
804 somg12 =
sin(omg12a); comg12 = -
cos(omg12a);
806 salp1 = cbet2 * somg12;
807 calp1 = sbet12a - cbet2 * sbet1 *
Math::sq(somg12) / (1 - comg12);
814 salp1 = 1; calp1 = 0;
829 bool diffp,
real& dlam12)
const 832 if (sbet1 == 0 && calp1 == 0)
839 salp0 = salp1 * cbet1,
842 real somg1, comg1, somg2, comg2, somg12, comg12, cchi1, cchi2, lam12;
845 ssig1 = sbet1; somg1 = salp0 * sbet1;
846 csig1 = comg1 = calp1 * cbet1;
848 cchi1 =
_f1 * dn1 * comg1;
857 salp2 = cbet2 != cbet1 ? salp0 / cbet2 : salp1;
862 calp2 = cbet2 != cbet1 ||
abs(sbet2) != -sbet1 ?
865 (cbet2 - cbet1) * (cbet1 + cbet2) :
866 (sbet1 - sbet2) * (sbet1 + sbet2))) / cbet2 :
870 ssig2 = sbet2; somg2 = salp0 * sbet2;
871 csig2 = comg2 = calp2 * cbet2;
873 cchi2 =
_f1 * dn2 * comg2;
879 sig12 =
atan2(
max(
real(0), csig1 * ssig2 - ssig1 * csig2),
880 csig1 * csig2 + ssig1 * ssig2);
883 somg12 =
max(
real(0), comg1 * somg2 - somg1 * comg2);
884 comg12 = comg1 * comg2 + somg1 * somg2;
889 schi12 =
max(
real(0), cchi1 * somg2 - somg1 * cchi2),
890 cchi12 = cchi1 * cchi2 + somg1 * somg2;
892 real eta =
atan2(schi12 * clam120 - cchi12 * slam120,
893 cchi12 * clam120 + schi12 * slam120);
895 (sig12 + (E.
deltaH(ssig2, csig2, dn2) - E.
deltaH(ssig1, csig1, dn1)));
896 lam12 = eta + deta12;
898 domg12 = deta12 +
atan2(schi12 * comg12 - cchi12 * somg12,
899 cchi12 * comg12 + schi12 * somg12);
902 dlam12 = - 2 *
_f1 * dn1 / sbet1;
905 Lengths(E, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
907 dummy, dlam12, dummy, dummy, dummy);
908 dlam12 *=
_f1 / (calp2 * cbet2);
920 for (
int l = 0;
l <
nC4_; ++
l) {
921 int m = nC4_ -
l - 1;
static T AngNormalize(T x)
Jet< T, N > cos(const Jet< T, N > &f)
real GenInverse(real lat1, real lon1, real lat2, real lon2, unsigned outmask, real &s12, real &salp1, real &calp1, real &salp2, real &calp2, real &m12, real &M12, real &M21, real &S12) const
static real CosSeries(real sinx, real cosx, const real c[], int n)
static const Pose3 T3(Rot3::Rodrigues(-90, 0, 0), Point3(1, 2, 3))
void Reset(real k2=0, real alpha2=0)
real InverseStart(EllipticFunction &E, real sbet1, real cbet1, real dn1, real sbet2, real cbet2, real dn2, real lam12, real slam12, real clam12, real &salp1, real &calp1, real &salp2, real &calp2, real &dnm) const
static bool isfinite(T x)
GeodesicLineExact InverseLine(real lat1, real lon1, real lat2, real lon2, unsigned caps=ALL) const
Math::real deltaE(real sn, real cn, real dn) const
Jet< T, N > sin(const Jet< T, N > &f)
Mathematical functions needed by GeographicLib.
void Lengths(const EllipticFunction &E, real sig12, real ssig1, real csig1, real dn1, real ssig2, real csig2, real dn2, real cbet1, real cbet2, unsigned outmask, real &s12s, real &m12a, real &m0, real &M12, real &M21) const
static void sincosd(T x, T &sinx, T &cosx)
static T AngDiff(T x, T y, T &e)
Elliptic integrals and functions.
GeodesicLineExact GenDirectLine(real lat1, real lon1, real azi1, bool arcmode, real s12_a12, unsigned caps=ALL) const
static void norm(T &x, T &y)
#define GEOGRAPHICLIB_VOLATILE
EIGEN_DEVICE_FUNC const AtanReturnType atan() const
static real Astroid(real x, real y)
static const Line3 l(Rot3(), 1, 1)
int EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
real Lambda12(real sbet1, real cbet1, real dn1, real sbet2, real cbet2, real dn2, real salp1, real calp1, real slam120, real clam120, real &salp2, real &calp2, real &sig12, real &ssig1, real &csig1, real &ssig2, real &csig2, EllipticFunction &E, real &domg12, bool diffp, real &dlam12) const
GeodesicExact(real a, real f)
Header for GeographicLib::GeodesicLineExact class.
Array< int, Dynamic, 1 > v
static T atan2d(T y, T x)
Eigen::Triplet< double > T
static T polyval(int N, const T p[], T x)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Namespace for GeographicLib.
EIGEN_DEVICE_FUNC const Scalar & q
static const unsigned maxit1_
Math::real deltaH(real sn, real cn, real dn) const
AnnoyingScalar atan2(const AnnoyingScalar &y, const AnnoyingScalar &x)
Exact geodesic calculations.
Header for GeographicLib::GeodesicExact class.
void C4f(real k2, real c[]) const
Exception handling for GeographicLib.
GeodesicLineExact DirectLine(real lat1, real lon1, real azi1, real s12, unsigned caps=ALL) const
friend class GeodesicLineExact
Math::real deltaD(real sn, real cn, real dn) const
Jet< T, N > sqrt(const Jet< T, N > &f)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
GeodesicLineExact ArcDirectLine(real lat1, real lon1, real azi1, real a12, unsigned caps=ALL) const
Math::real GenDirect(real lat1, real lon1, real azi1, bool arcmode, real s12_a12, unsigned outmask, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
GeodesicLineExact Line(real lat1, real lon1, real azi1, unsigned caps=ALL) const
#define GEOGRAPHICLIB_PANIC
static const GeodesicExact & WGS84()