c# - Haversine formula Unity -


so i'm trying use haversine formula in unity distance between 2 different points (latitude , longitud given). code working (no errors) keep gettting wrong result. followed entire formula don't know math/code problem is. idea?

here's code:

 public float lat1 = 42.239616f;  public float lat2 = -8.72304f;  public float lon1 = 42.239659f;  public float lon2 = -8.722305f;   void operacion(){  float r = 6371000; // metres  float omega1 = ((lat1/180)*mathf.pi);  float omega2 = ((lat2/180)*mathf.pi);  float variacionomega1 = (((lat2 - lat1)/180)*mathf.pi);  float variacionomega2 = (((lon2 - lon1) / 180) * mathf.pi);  float = mathf.sin(variacionomega1/2) * mathf.sin(variacionomega1/2) +              mathf.cos(omega1) * mathf.cos(omega2) *              mathf.sin(variacionomega2/2) * mathf.sin(variacionomega2/2);  float c = 2 * mathf.atan2(mathf.sqrt(a), mathf.sqrt(1-a));   float d = r * c;  } 

i think line incorrect:

float c = 2 * mathf.atan2(mathf.sqrt(a), mathf.sqrt(1-a)); 

updated:

the correct way be:

float c = 2 * mathf.asin(mathf.sqrt(a)); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -