Returns the "distance" in radians (about the spheres centre) between two positions.

You're viewing an older version of this page (#486). View the current version.

View versions (6)

Interface

#include <codecogs/maths/geometry/spherical/angulardistance.h>

using namespace Maths::Geometry::Spherical;

Overview

Calculates the angular distance between two points on the surface of a sphere relative to the centre of the sphere.

This calculation is made using:

dist = \cos^{-1} \left [ \sin(a_{lat}) \sin(b_{lat}) + \cos(a_{lat}) \cos(b_{lat}) \cos(b_{long} - a_{long}) \right ]
(1)

where a and b are the start and end location.

Example 1

#include <stdio.h>
#include <codecogs/maths/geometry/spherical/angularDistance.h>

int main()
{
  Position start(10,-90);
  Position end(45,20);
  printf("Angular Distance in Radians = %lf", angularDistance(start, end)); 
	return 0;
}

Output:

Angular Distance in Radians = 1.686437

Parameters

start
the first position [Latitude, Longitude].
end
the second position [latitude, Longitude].

Returns

the distance in radian about the center of the sphere.
GPL Licence — free for non commercial use. See Licence details.

FUNCTION

distance

Applies a simple conversion to the distance calculated by angularDistance to give a more conventional measure of distance according to the specified conversion ratio. This is simple the circumference of the sphere divided by 2 \pi. For example, with the planet earth on degree is divided into 60, which is called 1 minute of arc. This is also one nautical mile. Therefore to convert radian to nautical miles (knots) you multiply by:

\frac{360.0 \cdot 60}{2 \pi}
(2)
DescriptionradToDist
Nautical Mile on Earth3437.7475 knots/radian
Miles on Earth3956.0881 miles/radian
kilometers on Earth6366.7070 km/radian

Example 1

#include <stdio.h>
#include <codecogs/maths/geometry/spherical/angulardistance.h>

int main()
{
  Position start(10,-90);
  Position end(45,20);
  printf("\nKnots = %lf", distance(start, end)); 
  printf("\nMiles = %lf", distance(start, end, 3956.0881)); 
	return 0;
}

Output:

Knots = 5797.543498
Miles = 6671.692101

Parameters

start
the first position [Latitude, Longitude].
end
the second position [latitude, Longitude].
radToDist
Default Value = 3437.7475

Returns

the distance to new position.