According to documentation double Point2D.DistanceTo(Point2D otherPoint)
"Finds the straight line distance to another point". That means you are supposed to be on a plain. The result units are the same as ones used to create Point2D
objects. But that has nothing to do with finding distances on the surface of the Earth. What you need is:
static void Main(string[] args)
{
var earthRadius = 6371; // km
var seattle = GetVector(47.6062, -122.3321);
var sanFrancisco = GetVector(37.7749, -122.4194);
var angle = seattle.AngleTo(sanFrancisco);
var distance = angle.Radians * earthRadius;
Console.WriteLine(distance);
}
private static UnitVector3D GetVector(double lat, double lon)
{
var tmp = UnitVector3D.ZAxis;
var latitude = Angle.FromDegrees(lat);
var longitude = Angle.FromDegrees(lon);
var vector = UnitVector3D.XAxis.Rotate(tmp, longitude);
tmp = UnitVector3D.ZAxis.CrossProduct(vector);
vector = vector.Rotate(tmp, latitude);
return vector;
}
The result is:
1093,21376382715
Check it is correct.
To get miles change earthRadius
value to one in miles.
Update:
GetVector
can be implemented another way:
private static UnitVector3D north = UnitVector3D.ZAxis;
private static UnitVector3D east = UnitVector3D.XAxis;
private static Point3D northPole = UnitVector3D.ZAxis.ToPoint3D();
private static Point3D southPole = (-1 * UnitVector3D.ZAxis).ToPoint3D();
private static UnitVector3D GetVector(double lat, double lon)
{
var longitude = Angle.FromDegrees(lon);
var direction = east.Rotate(north, longitude);
var meridian = Circle3D.FromPoints(northPole, southPole, direction.ToPoint3D());
var normal = meridian.Axis;
var latitude = Angle.FromDegrees(lat);
return direction.Rotate(normal, latitude);
}