SphericalDistance[{θ1,ϕ1},{θ2,ϕ2}]
returns the great-circle distance between points {θ1,ϕ1} and {θ2,ϕ2} on the surface of a unit sphere.
SphericalDistance[{θ1,1,θ1,2,…,ϕ1},{θ2,1,θ2,2,…,ϕ2}]
returns the geodesic distance between arbitrary-dimensional points on the surface of a unit hypersphere.
SphericalDistance
SphericalDistance[{θ1,ϕ1},{θ2,ϕ2}]
returns the great-circle distance between points {θ1,ϕ1} and {θ2,ϕ2} on the surface of a unit sphere.
SphericalDistance[{θ1,1,θ1,2,…,ϕ1},{θ2,1,θ2,2,…,ϕ2}]
returns the geodesic distance between arbitrary-dimensional points on the surface of a unit hypersphere.
Details
- Spherical or hyperspherical coordinate vectors use the same conventions of CoordinateChartData and CoordinateTransformData, but with the leading r coordinate dropped.
- The geodesic distance on the surface of a radius-r hypersphere can be obtained by multiplying the result of SphericalDistance by radius r.
- Points on a 2D sphere can also be specified using GeoPosition[{lat,lon}] notation, with latitudes and longitudes in degrees.
- SphericalDistance threads over lists of points, with SphericalDistance[point,points] returning a list of distances, and SphericalDistance[points1,points2] returning a matrix of distances.
- When working with numerical data, SphericalDistance does not accept complex-valued inputs and returns only real-valued outputs.
Examples
open all close allBasic Examples (3)
The distance between a pair of points on the unit sphere:
SphericalDistance[{Pi / 4, 0}, {Pi / 3, Pi / 4}]The distance between a pair of points on the unit 3-sphere:
SphericalDistance[{0.52, 0.63, 0.78}, {1.05, 1.57, 3.14}]Take several points on the equator of the sphere:
pts = {{Pi / 2, 0}, {Pi / 2, Pi / 2}, {Pi / 2, Pi}, {Pi / 2, 3Pi / 2}}Show that they are all equidistant from the north pole:
SphericalDistance[{0, 0}, pts]Scope (5)
SphericalDistance accepts exact numerical inputs:
SphericalDistance[{Pi / 6, Pi / 5, Pi / 4}, {Pi / 3, Pi / 2, Pi}]SphericalDistance accepts arbitrary-precision numerical inputs:
SphericalDistance[N[{Pi / 6, Pi / 5, Pi / 4}, 35], N[{Pi / 3, Pi / 2, Pi}, 35]]SphericalDistance works with symbolic inputs:
SphericalDistance[{a, b}, {c, d}]Calculate a rectangular DistanceMatrix and display the results with ArrayPlot:
SeedRandom[1234];
ArrayPlot[SphericalDistance[RandomReal[Pi, {5, 4}], RandomReal[Pi, {10, 4}]]]SphericalDistance accepts points in GeoPosition[{lat,lon}] notation:
SphericalDistance[GeoPosition[{80.0, 87.0}], GeoPosition[{50.0, 135.3}]]Use GeoPosition lists of points:
SphericalDistance[GeoPosition[{{80.0, 87.0}, {50.0, 60.0}}], GeoPosition[{50.0, 135.3}]]Applications (3)
Generate three points in an octant of the unit sphere:
SeedRandom[1234];
pts = RandomReal[Pi / 2, {3, 2}]Find edge lengths of the corresponding spherical triangle:
distances = SphericalDistance@@@Subsets[pts, {2}]Verify the spherical triangle inequality:
AllTrue[{{{1, 2}, 3}, {{2, 3}, 1}, {{3, 1}, 2}}, Function[Greater[Total[distances[[First[#]]]],
distances[[Last[#]]]]]]Define a parametric trajectory in spherical coordinates:
fun = Function[t, {Pi / 2 + Pi / 4 Cos[2t], t}]Represent the curve as a series of points and plot:
curve = N[fun /@ Range[0, 2Pi, 2Pi / 1000]];Graphics3D[{Darker[Blue], Thick,
Line[Transpose[FromSphericalCoordinates[{1, θ, ϕ}] /. {θ -> First[Transpose[curve]], ϕ -> Last[Transpose[curve]]}]], Opacity[.75], LightGray, Sphere[]}, Lighting -> AmbientLight[White],
ViewVertical -> {0, 0, 1}, ViewPoint -> {85, 315, 53}, Boxed -> False
]Estimate the curve's arc length:
Total[MapApply[SphericalDistance, Partition[curve, 2, 1]]]Take the angular coordinates for the vertices of an octahedron:
octahedron = Join[{{0, 0}, {Pi, 0}}, {Pi / 2, # Pi / 2}& /@ Range[0, 3]]Compute distances from one point to all others:
SphericalDistance[First[octahedron], octahedron]Find the symmetric matrix of distances between any pair of points:
SphericalDistance[octahedron, octahedron]SymmetricMatrixQ[%]Properties & Relations (5)
Calculate an angular distance along the great circle
:
SphericalDistance[{Pi / 2, Pi / 5}, {Pi / 2, Pi / 2}]Calculate the same distance along the great circle
:
SphericalDistance[{Pi / 5, Pi}, {Pi / 2, Pi}]Both results are just the difference of component values:
Pi / 2 - Pi / 5Choose two points on a sphere:
SeedRandom[1234];
{a, b} = RandomReal[Pi, {2, 2}]Convert to Cartesian coordinates on a unit sphere:
{p, q} = FromSphericalCoordinates[Prepend[#, 1]& /@ {a, b}]Compare the results of SphericalDistance and VectorAngle:
SphericalDistance[a, b]VectorAngle[p, q]% - %%The result of EuclideanDistance is always less than the result of SphericalDistance:
EuclideanDistance[p, q]SphericalDistance[a, b]Locate two stars in the constellation Orion:
stars = {Entity["Star", "Rigel"], Entity["Star", "Betelgeuse"]};AstroGraphics[stars,
AstroReferenceFrame -> "Equatorial", AstroRange -> Quantity[15, "AngularDegrees"]]Calculate their angular separation in radians:
Apply[SphericalDistance,
Times[{90, 0} - AstroPosition[#, "Equatorial"]["Data"][[{2, 1}]],
Degree]& /@ stars]Compare with the result of AstroAngularSeparation:
Normal[AstroAngularSeparation[#1, #2, Entity["Star", "Sun"]]&@@stars ]Specify coordinates using GeoPosition:
p = GeoPosition[{80.0, 87.0}];
q = GeoPosition[{50.0, 135.3}];SphericalDistance[p, q]Compute the GeoDistance on an ellipsoidal Earth:
GeoDistance[p, q]Divide by Earth's average radius to a comparable result:
Divide[%, Entity["Planet", "Earth"]["Radius"]]Calculate a symbolic distance between arbitrary points on a sphere:
SphericalDistance[{a, b}, {c, d}]Compare with the result of VectorAngle, simplified over the reals:
Simplify[VectorAngle[FromPolarCoordinates[{1, a, b}], FromPolarCoordinates[{1, c, d}]], {a, b, c, d}∈Reals]Possible Issues (1)
Different usages of SphericalDistance may return different results:
res1 = SphericalDistance[{a1, a2, a3}, {{b1, b2, b3}}]res2 = SphericalDistance[{a1, a2, a3}, {b1, b2, b3}]Check that both results are equivalent:
First[res1] == res2//SimplifyNeat Examples (1)
List spherical coordinates for the vertices of a tetrahedron:
tetrahedronPts = Function[{
{#1, #2}, {Pi - #1, -#2}, {Pi - #1, 3#2}, {#1, -3#2}
}][ArcTan[Sqrt[2]], Pi / 4]Plot the tetrahedron with arcs between its vertices:
With[{cartesian = FromSphericalCoordinates[
Prepend[#, 1]]& /@ tetrahedronPts},
Graphics3D[{Line /@ Subsets[cartesian, {2}],
Red, Line[Nest[Riffle[#,
Normalize @* Mean /@ Partition[#, 2, 1]
]&, #, 5]]& /@ Subsets[cartesian, {2}],
LightGray, Opacity[.5], Sphere[]},
Lighting -> AmbientLight[White],
Boxed -> False, ViewVertical -> {0, 0, 1},
ViewPoint -> {2, -3, 4}
]
]Verify all points have equal angular separation:
SphericalDistance[tetrahedronPts, tetrahedronPts]History
Text
Wolfram Research (2023), SphericalDistance, Wolfram Language function, https://reference.wolfram.com/language/ref/SphericalDistance.html.
CMS
Wolfram Language. 2023. "SphericalDistance." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SphericalDistance.html.
APA
Wolfram Language. (2023). SphericalDistance. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SphericalDistance.html
BibTeX
@misc{reference.wolfram_2026_sphericaldistance, author="Wolfram Research", title="{SphericalDistance}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/SphericalDistance.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sphericaldistance, organization={Wolfram Research}, title={SphericalDistance}, year={2023}, url={https://reference.wolfram.com/language/ref/SphericalDistance.html}, note=[Accessed: 13-June-2026]}