In differential geometry, a geodesic is the “straightest possible” curve constrained to lie on a surface.
Intuitively, if you draw a curve on a surface and then locally “pull it tight” without lifting it off the surface, it tends
to approach a geodesic. A key property is that geodesics are (at least locally) length-minimizing paths:
among nearby curves with the same endpoints, the geodesic has the shortest surface length. This generalizes a familiar fact
from the plane: straight line segments minimize distance between two points.
The surface length of a curve \(X(t)\) in 3D is computed by the arc-length integral
\[
L=\int_{t_0}^{t_1}\lVert X'(t)\rVert\,dt.
\]
When the curve is restricted to a surface (for example, a sphere or a torus), the geodesic problem becomes a constrained
optimization problem: minimize \(L\) while keeping \(X(t)\) on the surface and fixing the endpoints. In full differential
geometry, one uses a metric (a way to measure lengths on the surface) and derives the geodesic equations via the calculus of
variations. Those equations can be difficult to solve explicitly, which is why numerical approximations are often used.
A sphere is the classic case where geodesics are known exactly. The shortest route between two points on a
sphere is an arc of a great circle—a circle formed by intersecting the sphere with a plane through the
sphere’s center. If the two surface points are represented by unit vectors \(u\) and \(v\), then the central angle between
them is \(\theta=\arccos(u\cdot v)\). The great-circle length is simply \(d=r\theta\), where \(r\) is the sphere radius.
Many implementations compute \(\theta\) using the haversine formula for stability when points are very close,
because it avoids loss of precision when \(\theta\) is tiny.
A torus (a donut shape) is more subtle. It can be parameterized by angles \((u,v)\) using
\(x=(R+r\cos v)\cos u\), \(y=(R+r\cos v)\sin u\), \(z=r\sin v\). Unlike the sphere, the shortest path between two points on
a torus can wrap around the central hole or around the tube, and there may be multiple locally shortest candidates.
A numerical “preview” strategy discretizes a curve into a polyline on the surface, then iteratively adjusts interior points to
reduce total length while keeping endpoints fixed. This resembles tightening a string laid on the surface: each adjustment aims
to shorten the sum of adjacent segment lengths. The result is a useful visualization of geodesic behavior, even though it is not
a proof of the global minimum in every case.
The 3D view in this calculator is designed to keep the surface centered while you rotate and zoom, so the path stays within the
frame. The animation slider reveals the curve progressively, which is a convenient way to see how the surface constraint bends
a “straight” route into a geodesic.