The nvector page
Position calculations – simple and exact solutions by means of nvector
nvector is used to replace latitude and longitude, making the calculations simple and nonsingular. Full accuracy is achieved for any global position (and for any distance).
This web page contains solutions to ten common geographical position calculations.
Background
Written by Kenneth Gade (PhD, Principal Scientist in the Navigation Group at FFI, Norwegian Defence Research Establishment).
For references, please cite:
Gade, K. (2010). A Nonsingular Horizontal Position Representation, The Journal of Navigation, Volume 63, Issue 03, pp 395417, July 2010.
Used worldwide for critical applications:
nvector is used worldwide, e.g. for navigation, traffic control, and surveillance, of aircraft, cars, ships and submarines/submersibles. One example is Thales, who is worldleading at air traffic management (ATM). Their newest generation of ATM system is based on nvector (replacing previous alternatives).
Solving ten common problems
We will now illustrate how ten common geographical position calculations can be solved using nvector. The solutions are also available as Matlab code (and as C++, C#, Python, JavaScript, and other languages).
Color coding for figures and variables:

Input (red): The initial input that is given

Output (green): The solution to be found
Example 1: A and B to delta
Problem

Assume WGS84 ellipsoid. The given depths are from the ellipsoid surface.

Use position A to define north, east, and down directions. (Due to the curvature of Earth and different directions to the North Pole, the north, east, and down directions will change (relative to Earth) for different places. Position A must be outside the poles for the north and east directions to be defined.
Solution
Example 2: B and delta to C
Problem
zyx2R.m
).Solution
n_E2R_EN.m
with n_E_and_wa2R_EL.m
. See Table 2 in Gade (2010) and the help text in n_E_and_wa2R_EL.m
for details.Example 3: ECEFvector to geodetic latitude
Problem
Solution
Example 4: Geodetic latitude to ECEFvector
Problem
Solution
n_EB_E2p_EB_E.m
. See also Appendix B in Gade (2010).In the remaining examples, we assume that a spherical Earth model is sufficiently accurate, and then the position functions used above are not needed. The examples demonstrate the simplicity of these calculations when using nvector instead of latitude and longitude. The nvector solutions are also nonsingular for all Earthpositions and work across the Date Line (180th meridian).
Example 5: Surface distance
Problem
See vector symbols explained for more details about the mathematical notation.
Given two positions A and B as
Solution
n_EA_E_and_n_EB_E2p_AB_E.m
from Example 1, and take the norm of the output vector.Example 6: Interpolated position
Problem
Solution
Example 7: Mean position/center
Problem 7
Solution 7
Details about the definition of the horizontal geographical mean position
Several definitions of a geographical mean/center/midpoint are possible. The solution given here can be described as the “center of gravity” of the given positions, and can be compared to the centroid of a geometrical shape. Informally, the found mean position can be described by the following: Assume a sphere that is a model of the Earth, and let the sphere roll freely on a horizontal plane (in a uniform gravitational field). Place weights at the given positions of the sphere, and the weights will pull one side of the sphere down due to the gravitation (assuming the positions are not antipodal). When the sphere is in equilibrium, the “center of gravity”position is the tangent point between the sphere and the plane.
Another possible way to define a midpoint is the position where the sum of surface distances (great circle distances) from the original positions is at a minimum. This midpoint is undefined when only two positions are given. If three positions are given in one dimension as 0, 0, and 3, this midpoint is at 0, while the arithmetic mean is 1. Iterations are probably needed to calculate this midpoint, and code for this is not included at this web site.
Example 8: A and azimuth/distance to B
Solution 8
Example 9: Intersection of two paths / triangulation
Problem 9
Solution 9
Example 10: Cross track distance (cross track error)
Problem 10
Solution 10
About the solutions
The four first examples are simply solved by using the functions provided for download. The functions are exact, and can use ellipsoidal or spherical Earth model. They are without iterations (i.e. on closed form), and WGS84 reference ellipsoid is used as default. Custom ellipsoids/spheres can be specified. The functions are based on nvector instead of latitude and longitude.
The last six examples are solved for spherical Earth, and then no functions are needed. Using nvector instead of latitude and longitude, these examples are quite straightforward to solve by simple vector algebra.
The solutions to all 10 examples are nonsingular, and they work equally well for all global positions (i.e. they work at the Poles, close to the Poles, and across the Date Line). The solutions also have full numerical accuracy for both short and long distances (they are numerically wellconditioned).