Gnomonic.java
Go to the documentation of this file.
1 
8 package net.sf.geographiclib;
9 
133 public class Gnomonic {
134  private static final double eps_ = 0.01 * Math.sqrt(GeoMath.epsilon);
135  private static final int numit_ = 10;
136  private Geodesic _earth;
137  private double _a, _f;
138 
145  public Gnomonic(Geodesic earth) {
146  _earth = earth;
147  _a = _earth.MajorRadius();
148  _f = _earth.Flattening();
149  }
150 
173  public GnomonicData Forward(double lat0, double lon0, double lat, double lon)
174  {
175  GeodesicData inv =
176  _earth.Inverse(lat0, lon0, lat, lon,
179  GnomonicData fwd =
180  new GnomonicData(lat0, lon0, lat, lon, Double.NaN, Double.NaN,
181  inv.azi2, inv.M12);
182 
183  if (inv.M12 > 0) {
184  double rho = inv.m12 / inv.M12;
185  Pair p = GeoMath.sincosd(inv.azi1);
186  fwd.x = rho * p.first;
187  fwd.y = rho * p.second;
188  }
189 
190  return fwd;
191  }
192 
217  public GnomonicData Reverse(double lat0, double lon0, double x, double y) {
218  GnomonicData rev =
219  new GnomonicData(lat0, lon0, Double.NaN, Double.NaN, x, y, Double.NaN,
220  Double.NaN);
221 
222  double azi0 = GeoMath.atan2d(x, y);
223  double rho = Math.hypot(x, y);
224  double s = _a * Math.atan(rho / _a);
225  boolean little = rho <= _a;
226 
227  if (!little)
228  rho = 1 / rho;
229 
230  GeodesicLine line =
231  _earth.Line(lat0, lon0, azi0, GeodesicMask.LATITUDE
235 
236  int count = numit_, trip = 0;
237  GeodesicData pos = null;
238 
239  while (count-- > 0) {
240  pos =
245 
246  if (trip > 0)
247  break;
248 
249  double ds =
250  little ? ((pos.m12 / pos.M12) - rho) * pos.M12 * pos.M12
251  : (rho - (pos.M12 / pos.m12)) * pos.m12 * pos.m12;
252  s -= ds;
253 
254  if (Math.abs(ds) <= eps_ * _a)
255  trip++;
256  }
257 
258  if (trip == 0)
259  return rev;
260 
261  rev.lat = pos.lat2;
262  rev.lon = pos.lon2;
263  rev.azi = pos.azi2;
264  rev.rk = pos.M12;
265 
266  return rev;
267  }
268 
273  public double MajorRadius() { return _a; }
274 
279  public double Flattening() { return _f; }
280 }
GeodesicData Position(double s12)
Scalar * y
static const double lat
static final double eps_
Definition: Gnomonic.java:134
static double atan2d(double y, double x)
Definition: GeoMath.java:274
GeodesicData Inverse(double lat1, double lon1, double lat2, double lon2)
Definition: Geodesic.java:615
const double lat0
RealScalar s
const double lon0
GeodesicLine Line(double lat1, double lon1, double azi1)
Definition: Geodesic.java:1130
static Pair sincosd(double x)
Definition: GeoMath.java:240
float * p
static const double lon
static final double epsilon
Definition: GeoMath.java:26
GnomonicData Reverse(double lat0, double lon0, double x, double y)
Definition: Gnomonic.java:217
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
GnomonicData Forward(double lat0, double lon0, double lat, double lon)
Definition: Gnomonic.java:173


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:09