GeographicLib  1.42
LocalCartesian.cpp
Go to the documentation of this file.
1 /**
2  * \file LocalCartesian.cpp
3  * \brief Implementation for GeographicLib::LocalCartesian class
4  *
5  * Copyright (c) Charles Karney (2008-2011) <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 
16  void LocalCartesian::Reset(real lat0, real lon0, real h0) {
17  _lat0 = lat0;
18  _lon0 = Math::AngNormalize(lon0);
19  _h0 = h0;
20  _earth.Forward(_lat0, _lon0, _h0, _x0, _y0, _z0);
21  real
22  phi = lat0 * Math::degree(),
23  sphi = sin(phi),
24  cphi = abs(_lat0) == 90 ? 0 : cos(phi),
25  lam = lon0 * Math::degree(),
26  slam = _lon0 == -180 ? 0 : sin(lam),
27  clam = abs(_lon0) == 90 ? 0 : cos(lam);
28  Geocentric::Rotation(sphi, cphi, slam, clam, _r);
29  }
30 
31  void LocalCartesian::MatrixMultiply(real M[dim2_]) const {
32  // M = r' . M
33  real t[dim2_];
34  copy(M, M + dim2_, t);
35  for (size_t i = 0; i < dim2_; ++i) {
36  size_t row = i / dim_, col = i % dim_;
37  M[i] = _r[row] * t[col] + _r[row+3] * t[col+3] + _r[row+6] * t[col+6];
38  }
39  }
40 
41  void LocalCartesian::IntForward(real lat, real lon, real h,
42  real& x, real& y, real& z,
43  real M[dim2_]) const {
44  real xc, yc, zc;
45  _earth.IntForward(lat, lon, h, xc, yc, zc, M);
46  xc -= _x0; yc -= _y0; zc -= _z0;
47  x = _r[0] * xc + _r[3] * yc + _r[6] * zc;
48  y = _r[1] * xc + _r[4] * yc + _r[7] * zc;
49  z = _r[2] * xc + _r[5] * yc + _r[8] * zc;
50  if (M)
51  MatrixMultiply(M);
52  }
53 
54  void LocalCartesian::IntReverse(real x, real y, real z,
55  real& lat, real& lon, real& h,
56  real M[dim2_]) const {
57  real
58  xc = _x0 + _r[0] * x + _r[1] * y + _r[2] * z,
59  yc = _y0 + _r[3] * x + _r[4] * y + _r[5] * z,
60  zc = _z0 + _r[6] * x + _r[7] * y + _r[8] * z;
61  _earth.IntReverse(xc, yc, zc, lat, lon, h, M);
62  if (M)
63  MatrixMultiply(M);
64  }
65 
66 } // namespace GeographicLib
static T AngNormalize(T x)
Definition: Math.hpp:428
void Reset(real lat0, real lon0, real h0=0)
Header for GeographicLib::LocalCartesian class.
GeographicLib::Math::real real
Definition: GeodSolve.cpp:32
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
static T degree()
Definition: Math.hpp:228