TransWikia.com

Calculation of intermediate points along shortest path not working correctly

Geographic Information Systems Asked on July 21, 2021

I am trying to implement the calculation of points along the shortest path using the algorithm shown here:

LatLng getGreatCirclePoint(double lat1, double lon1, double lat2, double lon2) {
  double d = 2*asin(sqrt(pow((sin((lat1-lat2)/2)),2) + cos(lat1)*cos(lat2)*pow((sin((lon1-lon2)/2)),2)));
  double f = 0.5;
  double A = sin((1-f)*d)/sin(d);
  double B = sin(f*d)/sin(d);
  double x = A*cos(lat1)*cos(lon1) +  B*cos(lat2)*cos(lon2);
  double y = A*cos(lat1)*sin(lon1) +  B*cos(lat2)*sin(lon2);
  double z = A*sin(lat1) + B*sin(lat2);
  double lat=atan2(z,sqrt(pow(x,2)+pow(y,2)));
  double lon=atan2(y,x);
  LatLng point = LatLng(lat,lon);
  return point;
}

Unfortunately this does not return the correct point but rather this here:

Wrong point between points on globe

Where did I go wrong in my implementation?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP