Hi! I am trying to get the Harvesine formula to work, but it seems to be returning a NaN value (not a number?).
Can you help me plz?
public float haversineDist(Vector3 pos1, Vector3 pos2)
{
//Centers the coordinates to the central point of the sphere
pos1 =pos1-centralPoint;
pos2 =pos2-centralPoint;
//Gets the spherical coordinates of the two points
Vector2 pos3=new Vector2(Mathf.Acos(pos1.z/radius), Mathf.Atan(pos1.y/pos1.x));
Vector2 pos4=new Vector2(Mathf.Acos(pos2.z/radius), Mathf.Atan(pos2.y/pos2.x));
float dLat = Mathf.Deg2Rad * (pos4.x - pos3.x);
float dLon = Mathf.Deg2Rad * (pos4.y - pos3.y);
//Harvesine distance
float d = 2*radius* Mathf.Asin(Mathf.Sqrt(Mathf.Sin(dLat/2)*Mathf.Sin(dLat/2)+ Mathf.Cos(pos3.x)*Mathf.Cos(pos4.x)*Mathf.Sin(dLon/2)*Mathf.Sin(dLon/2)));
//This print is to check if it is NaN
print(d);
return d;
}
Ty for your time.
Dydra