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