GeographicLib  2.0
LambertConformalConic.cpp
Go to the documentation of this file.
1 /**
2  * \file LambertConformalConic.cpp
3  * \brief Implementation for GeographicLib::LambertConformalConic class
4  *
5  * Copyright (c) Charles Karney (2010-2022) <charles@karney.com> and licensed
6  * under the MIT/X11 License. For more information, see
7  * https://geographiclib.sourceforge.io/
8  **********************************************************************/
9 
11 
12 namespace GeographicLib {
13 
14  using namespace std;
15 
17  real stdlat, real k0)
18  : eps_(numeric_limits<real>::epsilon())
19  , epsx_(Math::sq(eps_))
20  , ahypover_(Math::digits() * log(real(numeric_limits<real>::radix)) + 2)
21  , _a(a)
22  , _f(f)
23  , _fm(1 - _f)
24  , _e2(_f * (2 - _f))
25  , _es((_f < 0 ? -1 : 1) * sqrt(fabs(_e2)))
26  {
27  if (!(isfinite(_a) && _a > 0))
28  throw GeographicErr("Equatorial radius is not positive");
29  if (!(isfinite(_f) && _f < 1))
30  throw GeographicErr("Polar semi-axis is not positive");
31  if (!(isfinite(k0) && k0 > 0))
32  throw GeographicErr("Scale is not positive");
33  if (!(fabs(stdlat) <= Math::qd))
34  throw GeographicErr("Standard latitude not in [-" + to_string(Math::qd)
35  + "d, " + to_string(Math::qd) + "d]");
36  real sphi, cphi;
37  Math::sincosd(stdlat, sphi, cphi);
38  Init(sphi, cphi, sphi, cphi, k0);
39  }
40 
42  real stdlat1, real stdlat2,
43  real k1)
44  : eps_(numeric_limits<real>::epsilon())
45  , epsx_(Math::sq(eps_))
46  , ahypover_(Math::digits() * log(real(numeric_limits<real>::radix)) + 2)
47  , _a(a)
48  , _f(f)
49  , _fm(1 - _f)
50  , _e2(_f * (2 - _f))
51  , _es((_f < 0 ? -1 : 1) * sqrt(fabs(_e2)))
52  {
53  if (!(isfinite(_a) && _a > 0))
54  throw GeographicErr("Equatorial radius is not positive");
55  if (!(isfinite(_f) && _f < 1))
56  throw GeographicErr("Polar semi-axis is not positive");
57  if (!(isfinite(k1) && k1 > 0))
58  throw GeographicErr("Scale is not positive");
59  if (!(fabs(stdlat1) <= Math::qd))
60  throw GeographicErr("Standard latitude 1 not in [-"
61  + to_string(Math::qd) + "d, "
62  + to_string(Math::qd) + "d]");
63  if (!(fabs(stdlat2) <= Math::qd))
64  throw GeographicErr("Standard latitude 2 not in [-"
65  + to_string(Math::qd) + "d, "
66  + to_string(Math::qd) + "d]");
67  real sphi1, cphi1, sphi2, cphi2;
68  Math::sincosd(stdlat1, sphi1, cphi1);
69  Math::sincosd(stdlat2, sphi2, cphi2);
70  Init(sphi1, cphi1, sphi2, cphi2, k1);
71  }
72 
74  real sinlat1, real coslat1,
75  real sinlat2, real coslat2,
76  real k1)
77  : eps_(numeric_limits<real>::epsilon())
78  , epsx_(Math::sq(eps_))
79  , ahypover_(Math::digits() * log(real(numeric_limits<real>::radix)) + 2)
80  , _a(a)
81  , _f(f)
82  , _fm(1 - _f)
83  , _e2(_f * (2 - _f))
84  , _es((_f < 0 ? -1 : 1) * sqrt(fabs(_e2)))
85  {
86  if (!(isfinite(_a) && _a > 0))
87  throw GeographicErr("Equatorial radius is not positive");
88  if (!(isfinite(_f) && _f < 1))
89  throw GeographicErr("Polar semi-axis is not positive");
90  if (!(isfinite(k1) && k1 > 0))
91  throw GeographicErr("Scale is not positive");
92  if (signbit(coslat1))
93  throw GeographicErr("Standard latitude 1 not in [-"
94  + to_string(Math::qd) + "d, "
95  + to_string(Math::qd) + "d]");
96  if (signbit(coslat2))
97  throw GeographicErr("Standard latitude 2 not in [-"
98  + to_string(Math::qd) + "d, "
99  + to_string(Math::qd) + "d]");
100  if (!(fabs(sinlat1) <= 1 && coslat1 <= 1) || (coslat1 == 0 && sinlat1 == 0))
101  throw GeographicErr("Bad sine/cosine of standard latitude 1");
102  if (!(fabs(sinlat2) <= 1 && coslat2 <= 1) || (coslat2 == 0 && sinlat2 == 0))
103  throw GeographicErr("Bad sine/cosine of standard latitude 2");
104  if (coslat1 == 0 || coslat2 == 0)
105  if (!(coslat1 == coslat2 && sinlat1 == sinlat2))
106  throw GeographicErr
107  ("Standard latitudes must be equal is either is a pole");
108  Init(sinlat1, coslat1, sinlat2, coslat2, k1);
109  }
110 
111  void LambertConformalConic::Init(real sphi1, real cphi1,
112  real sphi2, real cphi2, real k1) {
113  {
114  real r;
115  r = hypot(sphi1, cphi1);
116  sphi1 /= r; cphi1 /= r;
117  r = hypot(sphi2, cphi2);
118  sphi2 /= r; cphi2 /= r;
119  }
120  bool polar = (cphi1 == 0);
121  cphi1 = fmax(epsx_, cphi1); // Avoid singularities at poles
122  cphi2 = fmax(epsx_, cphi2);
123  // Determine hemisphere of tangent latitude
124  _sign = sphi1 + sphi2 >= 0 ? 1 : -1;
125  // Internally work with tangent latitude positive
126  sphi1 *= _sign; sphi2 *= _sign;
127  if (sphi1 > sphi2) {
128  swap(sphi1, sphi2); swap(cphi1, cphi2); // Make phi1 < phi2
129  }
130  real
131  tphi1 = sphi1/cphi1, tphi2 = sphi2/cphi2, tphi0;
132  //
133  // Snyder: 15-8: n = (log(m1) - log(m2))/(log(t1)-log(t2))
134  //
135  // m = cos(bet) = 1/sec(bet) = 1/sqrt(1+tan(bet)^2)
136  // bet = parametric lat, tan(bet) = (1-f)*tan(phi)
137  //
138  // t = tan(pi/4-chi/2) = 1/(sec(chi) + tan(chi)) = sec(chi) - tan(chi)
139  // log(t) = -asinh(tan(chi)) = -psi
140  // chi = conformal lat
141  // tan(chi) = tan(phi)*cosh(xi) - sinh(xi)*sec(phi)
142  // xi = eatanhe(sin(phi)), eatanhe(x) = e * atanh(e*x)
143  //
144  // n = (log(sec(bet2))-log(sec(bet1)))/(asinh(tan(chi2))-asinh(tan(chi1)))
145  //
146  // Let log(sec(bet)) = b(tphi), asinh(tan(chi)) = c(tphi)
147  // Then n = Db(tphi2, tphi1)/Dc(tphi2, tphi1)
148  // In limit tphi2 -> tphi1, n -> sphi1
149  //
150  real
151  tbet1 = _fm * tphi1, scbet1 = hyp(tbet1),
152  tbet2 = _fm * tphi2, scbet2 = hyp(tbet2);
153  real
154  scphi1 = 1/cphi1,
155  xi1 = Math::eatanhe(sphi1, _es), shxi1 = sinh(xi1), chxi1 = hyp(shxi1),
156  tchi1 = chxi1 * tphi1 - shxi1 * scphi1, scchi1 = hyp(tchi1),
157  scphi2 = 1/cphi2,
158  xi2 = Math::eatanhe(sphi2, _es), shxi2 = sinh(xi2), chxi2 = hyp(shxi2),
159  tchi2 = chxi2 * tphi2 - shxi2 * scphi2, scchi2 = hyp(tchi2),
160  psi1 = asinh(tchi1);
161  if (tphi2 - tphi1 != 0) {
162  // Db(tphi2, tphi1)
163  real num = Dlog1p(Math::sq(tbet2)/(1 + scbet2),
164  Math::sq(tbet1)/(1 + scbet1))
165  * Dhyp(tbet2, tbet1, scbet2, scbet1) * _fm;
166  // Dc(tphi2, tphi1)
167  real den = Dasinh(tphi2, tphi1, scphi2, scphi1)
168  - Deatanhe(sphi2, sphi1) * Dsn(tphi2, tphi1, sphi2, sphi1);
169  _n = num/den;
170 
171  if (_n < 1/real(4))
172  _nc = sqrt((1 - _n) * (1 + _n));
173  else {
174  // Compute nc = cos(phi0) = sqrt((1 - n) * (1 + n)), evaluating 1 - n
175  // carefully. First write
176  //
177  // Dc(tphi2, tphi1) * (tphi2 - tphi1)
178  // = log(tchi2 + scchi2) - log(tchi1 + scchi1)
179  //
180  // then den * (1 - n) =
181  // (log((tchi2 + scchi2)/(2*scbet2)) -
182  // log((tchi1 + scchi1)/(2*scbet1))) / (tphi2 - tphi1)
183  // = Dlog1p(a2, a1) * (tchi2+scchi2 + tchi1+scchi1)/(4*scbet1*scbet2)
184  // * fm * Q
185  //
186  // where
187  // a1 = ( (tchi1 - scbet1) + (scchi1 - scbet1) ) / (2 * scbet1)
188  // Q = ((scbet2 + scbet1)/fm)/((scchi2 + scchi1)/D(tchi2, tchi1))
189  // - (tbet2 + tbet1)/(scbet2 + scbet1)
190  real t;
191  {
192  real
193  // s1 = (scbet1 - scchi1) * (scbet1 + scchi1)
194  s1 = (tphi1 * (2 * shxi1 * chxi1 * scphi1 - _e2 * tphi1) -
195  Math::sq(shxi1) * (1 + 2 * Math::sq(tphi1))),
196  s2 = (tphi2 * (2 * shxi2 * chxi2 * scphi2 - _e2 * tphi2) -
197  Math::sq(shxi2) * (1 + 2 * Math::sq(tphi2))),
198  // t1 = scbet1 - tchi1
199  t1 = tchi1 < 0 ? scbet1 - tchi1 : (s1 + 1)/(scbet1 + tchi1),
200  t2 = tchi2 < 0 ? scbet2 - tchi2 : (s2 + 1)/(scbet2 + tchi2),
201  a2 = -(s2 / (scbet2 + scchi2) + t2) / (2 * scbet2),
202  a1 = -(s1 / (scbet1 + scchi1) + t1) / (2 * scbet1);
203  t = Dlog1p(a2, a1) / den;
204  }
205  // multiply by (tchi2 + scchi2 + tchi1 + scchi1)/(4*scbet1*scbet2) * fm
206  t *= ( ( (tchi2 >= 0 ? scchi2 + tchi2 : 1/(scchi2 - tchi2)) +
207  (tchi1 >= 0 ? scchi1 + tchi1 : 1/(scchi1 - tchi1)) ) /
208  (4 * scbet1 * scbet2) ) * _fm;
209 
210  // Rewrite
211  // Q = (1 - (tbet2 + tbet1)/(scbet2 + scbet1)) -
212  // (1 - ((scbet2 + scbet1)/fm)/((scchi2 + scchi1)/D(tchi2, tchi1)))
213  // = tbm - tam
214  // where
215  real tbm = ( ((tbet1 > 0 ? 1/(scbet1+tbet1) : scbet1 - tbet1) +
216  (tbet2 > 0 ? 1/(scbet2+tbet2) : scbet2 - tbet2)) /
217  (scbet1+scbet2) );
218 
219  // tam = (1 - ((scbet2+scbet1)/fm)/((scchi2+scchi1)/D(tchi2, tchi1)))
220  //
221  // Let
222  // (scbet2 + scbet1)/fm = scphi2 + scphi1 + dbet
223  // (scchi2 + scchi1)/D(tchi2, tchi1) = scphi2 + scphi1 + dchi
224  // then
225  // tam = D(tchi2, tchi1) * (dchi - dbet) / (scchi1 + scchi2)
226  real
227  // D(tchi2, tchi1)
228  dtchi = den / Dasinh(tchi2, tchi1, scchi2, scchi1),
229  // (scbet2 + scbet1)/fm - (scphi2 + scphi1)
230  dbet = (_e2/_fm) * ( 1 / (scbet2 + _fm * scphi2) +
231  1 / (scbet1 + _fm * scphi1) );
232 
233  // dchi = (scchi2 + scchi1)/D(tchi2, tchi1) - (scphi2 + scphi1)
234  // Let
235  // tzet = chxiZ * tphi - shxiZ * scphi
236  // tchi = tzet + nu
237  // scchi = sczet + mu
238  // where
239  // xiZ = eatanhe(1), shxiZ = sinh(xiZ), chxiZ = cosh(xiZ)
240  // nu = scphi * (shxiZ - shxi) - tphi * (chxiZ - chxi)
241  // mu = - scphi * (chxiZ - chxi) + tphi * (shxiZ - shxi)
242  // then
243  // dchi = ((mu2 + mu1) - D(nu2, nu1) * (scphi2 + scphi1)) /
244  // D(tchi2, tchi1)
245  real
246  xiZ = Math::eatanhe(real(1), _es),
247  shxiZ = sinh(xiZ), chxiZ = hyp(shxiZ),
248  // These are differences not divided differences
249  // dxiZ1 = xiZ - xi1; dshxiZ1 = shxiZ - shxi; dchxiZ1 = chxiZ - chxi
250  dxiZ1 = Deatanhe(real(1), sphi1)/(scphi1*(tphi1+scphi1)),
251  dxiZ2 = Deatanhe(real(1), sphi2)/(scphi2*(tphi2+scphi2)),
252  dshxiZ1 = Dsinh(xiZ, xi1, shxiZ, shxi1, chxiZ, chxi1) * dxiZ1,
253  dshxiZ2 = Dsinh(xiZ, xi2, shxiZ, shxi2, chxiZ, chxi2) * dxiZ2,
254  dchxiZ1 = Dhyp(shxiZ, shxi1, chxiZ, chxi1) * dshxiZ1,
255  dchxiZ2 = Dhyp(shxiZ, shxi2, chxiZ, chxi2) * dshxiZ2,
256  // mu1 + mu2
257  amu12 = (- scphi1 * dchxiZ1 + tphi1 * dshxiZ1
258  - scphi2 * dchxiZ2 + tphi2 * dshxiZ2),
259  // D(xi2, xi1)
260  dxi = Deatanhe(sphi1, sphi2) * Dsn(tphi2, tphi1, sphi2, sphi1),
261  // D(nu2, nu1)
262  dnu12 =
263  ( (_f * 4 * scphi2 * dshxiZ2 > _f * scphi1 * dshxiZ1 ?
264  // Use divided differences
265  (dshxiZ1 + dshxiZ2)/2 * Dhyp(tphi1, tphi2, scphi1, scphi2)
266  - ( (scphi1 + scphi2)/2
267  * Dsinh(xi1, xi2, shxi1, shxi2, chxi1, chxi2) * dxi ) :
268  // Use ratio of differences
269  (scphi2 * dshxiZ2 - scphi1 * dshxiZ1)/(tphi2 - tphi1))
270  + ( (tphi1 + tphi2)/2 * Dhyp(shxi1, shxi2, chxi1, chxi2)
271  * Dsinh(xi1, xi2, shxi1, shxi2, chxi1, chxi2) * dxi )
272  - (dchxiZ1 + dchxiZ2)/2 ),
273  // dtchi * dchi
274  dchia = (amu12 - dnu12 * (scphi2 + scphi1)),
275  tam = (dchia - dtchi * dbet) / (scchi1 + scchi2);
276  t *= tbm - tam;
277  _nc = sqrt(fmax(real(0), t) * (1 + _n));
278  }
279  {
280  real r = hypot(_n, _nc);
281  _n /= r;
282  _nc /= r;
283  }
284  tphi0 = _n / _nc;
285  } else {
286  tphi0 = tphi1;
287  _nc = 1/hyp(tphi0);
288  _n = tphi0 * _nc;
289  if (polar)
290  _nc = 0;
291  }
292 
293  _scbet0 = hyp(_fm * tphi0);
294  real shxi0 = sinh(Math::eatanhe(_n, _es));
295  _tchi0 = tphi0 * hyp(shxi0) - shxi0 * hyp(tphi0); _scchi0 = hyp(_tchi0);
296  _psi0 = asinh(_tchi0);
297 
298  _lat0 = atan(_sign * tphi0) / Math::degree();
299  _t0nm1 = expm1(- _n * _psi0); // Snyder's t0^n - 1
300  // a * k1 * m1/t1^n = a * k1 * m2/t2^n = a * k1 * n * (Snyder's F)
301  // = a * k1 / (scbet1 * exp(-n * psi1))
302  _scale = _a * k1 / scbet1 *
303  // exp(n * psi1) = exp(- (1 - n) * psi1) * exp(psi1)
304  // with (1-n) = nc^2/(1+n) and exp(-psi1) = scchi1 + tchi1
305  exp( - (Math::sq(_nc)/(1 + _n)) * psi1 )
306  * (tchi1 >= 0 ? scchi1 + tchi1 : 1 / (scchi1 - tchi1));
307  // Scale at phi0 = k0 = k1 * (scbet0*exp(-n*psi0))/(scbet1*exp(-n*psi1))
308  // = k1 * scbet0/scbet1 * exp(n * (psi1 - psi0))
309  // psi1 - psi0 = Dasinh(tchi1, tchi0) * (tchi1 - tchi0)
310  _k0 = k1 * (_scbet0/scbet1) *
311  exp( - (Math::sq(_nc)/(1 + _n)) *
312  Dasinh(tchi1, _tchi0, scchi1, _scchi0) * (tchi1 - _tchi0))
313  * (tchi1 >= 0 ? scchi1 + tchi1 : 1 / (scchi1 - tchi1)) /
314  (_scchi0 + _tchi0);
315  _nrho0 = polar ? 0 : _a * _k0 / _scbet0;
316  {
317  // Figure _drhomax using code at beginning of Forward with lat = -90
318  real
319  sphi = -1, cphi = epsx_,
320  tphi = sphi/cphi,
321  scphi = 1/cphi, shxi = sinh(Math::eatanhe(sphi, _es)),
322  tchi = hyp(shxi) * tphi - shxi * scphi, scchi = hyp(tchi),
323  psi = asinh(tchi),
324  dpsi = Dasinh(tchi, _tchi0, scchi, _scchi0) * (tchi - _tchi0);
325  _drhomax = - _scale * (2 * _nc < 1 && dpsi != 0 ?
326  (exp(Math::sq(_nc)/(1 + _n) * psi ) *
327  (tchi > 0 ? 1/(scchi + tchi) : (scchi - tchi))
328  - (_t0nm1 + 1))/(-_n) :
329  Dexp(-_n * psi, -_n * _psi0) * dpsi);
330  }
331  }
332 
334  static const LambertConformalConic mercator(Constants::WGS84_a(),
336  real(0), real(1));
337  return mercator;
338  }
339 
340  void LambertConformalConic::Forward(real lon0, real lat, real lon,
341  real& x, real& y,
342  real& gamma, real& k) const {
343  lon = Math::AngDiff(lon0, lon);
344  // From Snyder, we have
345  //
346  // theta = n * lambda
347  // x = rho * sin(theta)
348  // = (nrho0 + n * drho) * sin(theta)/n
349  // y = rho0 - rho * cos(theta)
350  // = nrho0 * (1-cos(theta))/n - drho * cos(theta)
351  //
352  // where nrho0 = n * rho0, drho = rho - rho0
353  // and drho is evaluated with divided differences
354  real sphi, cphi;
355  Math::sincosd(Math::LatFix(lat) * _sign, sphi, cphi);
356  cphi = fmax(epsx_, cphi);
357  real
358  lam = lon * Math::degree(),
359  tphi = sphi/cphi, scbet = hyp(_fm * tphi),
360  scphi = 1/cphi, shxi = sinh(Math::eatanhe(sphi, _es)),
361  tchi = hyp(shxi) * tphi - shxi * scphi, scchi = hyp(tchi),
362  psi = asinh(tchi),
363  theta = _n * lam, stheta = sin(theta), ctheta = cos(theta),
364  dpsi = Dasinh(tchi, _tchi0, scchi, _scchi0) * (tchi - _tchi0),
365  drho = - _scale * (2 * _nc < 1 && dpsi != 0 ?
366  (exp(Math::sq(_nc)/(1 + _n) * psi ) *
367  (tchi > 0 ? 1/(scchi + tchi) : (scchi - tchi))
368  - (_t0nm1 + 1))/(-_n) :
369  Dexp(-_n * psi, -_n * _psi0) * dpsi);
370  x = (_nrho0 + _n * drho) * (_n != 0 ? stheta / _n : lam);
371  y = _nrho0 *
372  (_n != 0 ?
373  (ctheta < 0 ? 1 - ctheta : Math::sq(stheta)/(1 + ctheta)) / _n : 0)
374  - drho * ctheta;
375  k = _k0 * (scbet/_scbet0) /
376  (exp( - (Math::sq(_nc)/(1 + _n)) * dpsi )
377  * (tchi >= 0 ? scchi + tchi : 1 / (scchi - tchi)) / (_scchi0 + _tchi0));
378  y *= _sign;
379  gamma = _sign * theta / Math::degree();
380  }
381 
382  void LambertConformalConic::Reverse(real lon0, real x, real y,
383  real& lat, real& lon,
384  real& gamma, real& k) const {
385  // From Snyder, we have
386  //
387  // x = rho * sin(theta)
388  // rho0 - y = rho * cos(theta)
389  //
390  // rho = hypot(x, rho0 - y)
391  // drho = (n*x^2 - 2*y*nrho0 + n*y^2)/(hypot(n*x, nrho0-n*y) + nrho0)
392  // theta = atan2(n*x, nrho0-n*y)
393  //
394  // From drho, obtain t^n-1
395  // psi = -log(t), so
396  // dpsi = - Dlog1p(t^n-1, t0^n-1) * drho / scale
397  y *= _sign;
398  real
399  // Guard against 0 * inf in computation of ny
400  nx = _n * x, ny = _n != 0 ? _n * y : 0, y1 = _nrho0 - ny,
401  den = hypot(nx, y1) + _nrho0, // 0 implies origin with polar aspect
402  // isfinite test is to avoid inf/inf
403  drho = ((den != 0 && isfinite(den))
404  ? (x*nx + y * (ny - 2*_nrho0)) / den
405  : den);
406  drho = fmin(drho, _drhomax);
407  if (_n == 0)
408  drho = fmax(drho, -_drhomax);
409  real
410  tnm1 = _t0nm1 + _n * drho/_scale,
411  dpsi = (den == 0 ? 0 :
412  (tnm1 + 1 != 0 ? - Dlog1p(tnm1, _t0nm1) * drho / _scale :
413  ahypover_));
414  real tchi;
415  if (2 * _n <= 1) {
416  // tchi = sinh(psi)
417  real
418  psi = _psi0 + dpsi, tchia = sinh(psi), scchi = hyp(tchia),
419  dtchi = Dsinh(psi, _psi0, tchia, _tchi0, scchi, _scchi0) * dpsi;
420  tchi = _tchi0 + dtchi; // Update tchi using divided difference
421  } else {
422  // tchi = sinh(-1/n * log(tn))
423  // = sinh((1-1/n) * log(tn) - log(tn))
424  // = + sinh((1-1/n) * log(tn)) * cosh(log(tn))
425  // - cosh((1-1/n) * log(tn)) * sinh(log(tn))
426  // (1-1/n) = - nc^2/(n*(1+n))
427  // cosh(log(tn)) = (tn + 1/tn)/2; sinh(log(tn)) = (tn - 1/tn)/2
428  real
429  tn = tnm1 + 1 == 0 ? epsx_ : tnm1 + 1,
430  sh = sinh( -Math::sq(_nc)/(_n * (1 + _n)) *
431  (2 * tn > 1 ? log1p(tnm1) : log(tn)) );
432  tchi = sh * (tn + 1/tn)/2 - hyp(sh) * (tnm1 * (tn + 1)/tn)/2;
433  }
434 
435  // log(t) = -asinh(tan(chi)) = -psi
436  gamma = atan2(nx, y1);
437  real
438  tphi = Math::tauf(tchi, _es),
439  scbet = hyp(_fm * tphi), scchi = hyp(tchi),
440  lam = _n != 0 ? gamma / _n : x / y1;
441  lat = Math::atand(_sign * tphi);
442  lon = lam / Math::degree();
443  lon = Math::AngNormalize(lon + Math::AngNormalize(lon0));
444  k = _k0 * (scbet/_scbet0) /
445  (exp(_nc != 0 ? - (Math::sq(_nc)/(1 + _n)) * dpsi : 0)
446  * (tchi >= 0 ? scchi + tchi : 1 / (scchi - tchi)) / (_scchi0 + _tchi0));
447  gamma /= _sign * Math::degree();
448  }
449 
450  void LambertConformalConic::SetScale(real lat, real k) {
451  if (!(isfinite(k) && k > 0))
452  throw GeographicErr("Scale is not positive");
453  if (!(fabs(lat) <= Math::qd))
454  throw GeographicErr("Latitude for SetScale not in [-"
455  + to_string(Math::qd) + "d, "
456  + to_string(Math::qd) + "d]");
457  if (fabs(lat) == Math::qd && !(_nc == 0 && lat * _n > 0))
458  throw GeographicErr("Incompatible polar latitude in SetScale");
459  real x, y, gamma, kold;
460  Forward(0, lat, 0, x, y, gamma, kold);
461  k /= kold;
462  _scale *= k;
463  _k0 *= k;
464  }
465 
466 } // namespace GeographicLib
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
Header for GeographicLib::LambertConformalConic class.
Exception handling for GeographicLib.
Definition: Constants.hpp:316
Lambert conformal conic projection.
LambertConformalConic(real a, real f, real stdlat, real k0)
void Reverse(real lon0, real x, real y, real &lat, real &lon, real &gamma, real &k) const
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
void SetScale(real lat, real k=real(1))
static const LambertConformalConic & Mercator()
Mathematical functions needed by GeographicLib.
Definition: Math.hpp:76
static T degree()
Definition: Math.hpp:200
static T LatFix(T x)
Definition: Math.hpp:299
static void sincosd(T x, T &sinx, T &cosx)
Definition: Math.cpp:106
static T sq(T x)
Definition: Math.hpp:212
static T tauf(T taup, T es)
Definition: Math.cpp:219
static T AngNormalize(T x)
Definition: Math.cpp:71
static T atand(T x)
Definition: Math.cpp:202
static T AngDiff(T x, T y, T &e)
Definition: Math.cpp:82
static T eatanhe(T x, T es)
Definition: Math.cpp:205
@ qd
degrees per quarter turn
Definition: Math.hpp:141
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
void swap(GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &a, GeographicLib::NearestNeighbor< dist_t, pos_t, distfun_t > &b)