/// <summary> /// Computes the angle defined by aBc using Al-Kashi. /// Warning: this method is not accurate for triangles in spheric environnement. /// </summary> /// <param name="point1">The point1.</param> /// <param name="point2">The point2.</param> /// <param name="point3">The point3.</param> /// <returns></returns> public static double ComputeAngle(LatLong a, LatLong b, LatLong c) { if (a == b || a == c || b == c) { return(double.NaN); } // Al-kashi: alpha = arccos (ab² + bc² - ac² / (2ab * bc)) double abSquare = SquareDistance(a, b); double bcSquare = SquareDistance(b, c); double acSquare = SquareDistance(a, c); return(RadianToDegree * Math.Acos((abSquare + bcSquare - acSquare) / (2 * Math.Sqrt(abSquare) * Math.Sqrt(bcSquare)))); }
/// <summary> /// Squares the distance. /// Warning: this method is poorly accurate. /// </summary> /// <param name="point1">The point1.</param> /// <param name="point2">The point2.</param> /// <returns></returns> public static double SquareDistance(LatLong point1, LatLong point2) { return(SquareDistance(point1.Latitude, point1.Longitude, point2.Latitude, point2.Longitude)); }
/// <summary> /// Compute the Haversine distance. /// </summary> /// <param name="pointA">The point A.</param> /// <param name="pointB">The point B.</param> /// <returns>The distance in kilometers.</returns> public static double HaversineDistance(LatLong pointA, LatLong pointB) { return(HaversineDistance(pointA.Latitude, pointA.Longitude, pointB.Latitude, pointB.Longitude)); }
/// <summary> /// Gets the distance (in kilometers) between two spherical points (in degrees). /// Warning: this method is poorly accurate. /// </summary> public static double Distance(LatLong point1, LatLong point2) { return(DegreeToKilometer(Math.Sqrt(SquareDistance(point1, point2)))); }