Question

I have entities in a simulation whose initial locations and paths are code using Java in decimal degrees. I need to scale the sensor radius (it's in nautical miles) and speed (nautical miles/hr) to match decimal degrees. The purpose is to visualize the sim in OpenMap and Google Earth.

I've seen How to convert Distance(miles) to degrees?, but the suggestions there don't work.

Any help is appreciated! I'm thinking it will involve using great circle distance formulas... but can't quite get it.

Was it helpful?

Solution

Ed Williams' Aviation Formula https://edwilliams.org/avform.htm is a good, and accessible, place to start. And I often reference http://movable-type.co.uk/scripts/latlong.html.

I am guessing that you need a vector of some sort (your question is a bit unclear).

What I use (in C, not Java) to calculate a fix-radial-distance is:

void polarToLatLong(double lat, double lon, double dist, double radial,
   double *outlat, double *outlon) {
   if (!dist) { // distance zero, so just return the point
      *outlat = lat;
      *outlon = lon;
   }
   else if (lat > 89.9999) { // North Pole singularity. Dist is in NM.
      *outlat = 90 - dist / 60;
      *outlon = fmod(radial + 180) - 180;
   }
   else { // normal case
      double sinlat, coslon;
      dist /= 3442; // = Earth's radius in nm (not WGS84!)
      sinlat = Sin(lat) * cos(dist) + Cos(lat) * sin(dist) * Cos(radial);
      *outlat = Arcsin(sinlat);
      coslon = (cos(dist) - Sin(lat) * sinlat) / (Cos(lat) * Cos(*outlat));
      *outlon = lon + (Sin(radial) >= 0 : -1 : 1) * Arccos(coslon);
   }
}

In the above code Sin(), with an upper-case S, is just a wrapper of sin() for degrees:

#define CLAMP(a,x,b) MIN(MAX(a, x), b) // GTK+ GLib version slightly different
double Sin(double deg)   {return sin(deg * (PI / 180));} // wrappers for degrees
double Cos(double deg)   {return cos(deg * (PI / 180));}
double Arcsin(double x)  {return asin(CLAMP(-1, x, 1)) * (180 / PI);}
double Arccos(double x)  {return acos(CLAMP(-1, x, 1)) * (180 / PI);}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top