# N-vector

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/N-vector
> Markdown URL: https://mediated.wiki/source/N-vector.md
> Source: https://en.wikipedia.org/wiki/N-vector
> Source revision: 1354853589
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{DISPLAYTITLE:''n''-vector}}
{{Other uses|K-vector (disambiguation){{!}}K-vector}}

The ''' ''n''-vector''' representation (also called '''geodetic normal''' or '''ellipsoid normal vector''') is a three-parameter [non-singular](/source/mathematical_singularity) representation well-suited for replacing [geodetic coordinates](/source/geodetic_coordinates) ([latitude](/source/latitude) and [longitude](/source/longitude)) for [horizontal position representation](/source/horizontal_position_representation) in mathematical calculations and computer algorithms.

Geometrically, the ''n''-vector for a given position on an [ellipsoid](/source/ellipsoid) is the outward-pointing [unit vector](/source/unit_vector) that is [normal](/source/surface_normal) in that position to the ellipsoid. For representing horizontal positions on Earth, the ellipsoid is a [reference ellipsoid](/source/reference_ellipsoid) and the vector is [decomposed](/source/Vector_decomposition) in an [Earth-centered Earth-fixed](/source/ECEF) [coordinate system](/source/coordinate_system). It behaves smoothly at all Earth positions, and it holds the mathematical [one-to-one](/source/Injective_function) property.

More generally, the concept can be applied to representing positions on the boundary of a strictly [convex](/source/Convex_set) [bounded subset](/source/bounded_subset) of ''k''-dimensional [Euclidean space](/source/Euclidean_space), provided that that boundary is a [differentiable manifold](/source/differentiable_manifold). In this general case, the ''n''-vector consists of ''k'' parameters.

==General properties==

A [normal vector](/source/normal_vector) to a strictly [convex](/source/convex_set) surface can be used to uniquely define a surface position. ''n''-vector is an  outward-pointing normal vector with [unit length](/source/unit_vector) used as a position representation. 
<ref name=Gade>{{cite journal |last1= Gade |first1= Kenneth |year= 2010 |title= A non-singular horizontal position representation |journal= The Journal of Navigation |publisher= Cambridge University Press |volume= 63 |issue= 3 |pages=395–417 |url=https://www.navlab.net/Publications/A_Nonsingular_Horizontal_Position_Representation.pdf|doi= 10.1017/S0373463309990415 |bibcode= 2010JNav...63..395G }}</ref>

For most applications the surface is the [reference ellipsoid](/source/reference_ellipsoid) of the Earth, and thus ''n''-vector is used to represent a horizontal position. Hence, the angle between ''n''-vector and the equatorial plane corresponds to [geodetic latitude](/source/geodetic_latitude), as shown in the figure.

thumb | upright=1.7 | alt=Alt |The direction of ''n''-vector corresponds to geodetic latitude

A surface position has two [degrees of freedom](/source/Degrees_of_freedom_(mechanics)), and thus two parameters are sufficient to represent any position on the surface. On the reference ellipsoid, [latitude](/source/latitude) and [longitude](/source/longitude) are common parameters for this purpose, but like all ''two-parameter representations'', they have [singularities](/source/mathematical_singularity). This is similar to [orientation](/source/Rotation_formalisms_in_three_dimensions), which has three degrees of freedom, but all ''three-parameter representations'' have singularities.<ref>{{cite journal |last1= Stuelpnagel |first1= John |year= 1964 |title= On the Parametrization of the Three-Dimensional Rotation Group |journal= SIAM Review |publisher= Society for Industrial and Applied Mathematics |volume= 6 |issue= 4 |pages=422–430 |doi=10.1137/1006093 |jstor=2027966|bibcode= 1964SIAMR...6..422S }}</ref> In both cases the singularities are avoided by adding an extra parameter, i.e. to use ''n''-vector (three parameters) to [represent horizontal position](/source/Horizontal_position_representation) and a unit [quaternion](/source/quaternion) (four parameters) to [represent orientation](/source/Rotation_formalisms_in_three_dimensions).

''n''-vector is a [one-to-one](/source/Injective_function) representation, meaning that any surface position corresponds to one unique ''n''-vector, and any ''n''-vector corresponds to one unique surface position. 

As a [Euclidean 3D vector](/source/Euclidean_vector), standard 3D [vector algebra](/source/Vector_calculus) can be used for the position calculations, and this makes ''n''-vector well-suited for most horizontal position calculations. For a general comparison of the various representations, see the [horizontal position representations page](/source/horizontal_position_representation).

== Converting latitude/longitude to ''n''-vector ==

Based on the definition of the [ECEF](/source/ECEF) coordinate system, called ''e'', it is clear that going from latitude/longitude to ''n''-vector, is achieved by:

:<math>\mathbf n^e=\left[ \begin{matrix}
   \cos (\mathrm{latitude})\cos (\mathrm{longitude})  \\
   \cos (\mathrm{latitude})\sin (\mathrm{longitude})  \\
   \sin (\mathrm{latitude})  \\
\end{matrix} \right]</math>

The superscript ''e'' means that ''n''-vector is [decomposed](/source/Vector_decomposition) in the coordinate system ''e'' (i.e. the first component is the [scalar projection](/source/Scalar_resolute) of ''n''-vector onto the ''x''-axis of ''e'', the second onto the ''y''-axis of ''e'' etc.). Note that the equation is exact both for spherical and ellipsoidal Earth model.

== Converting ''n''-vector to latitude/longitude ==

From the three components of ''n''-vector, <math>n_x^e</math>, <math>n_y^e</math>, and <math>n_z^e</math>, latitude can be found by using:

:<math>\mathrm{latitude}=\arcsin\left( n_z^e \right)=\arctan\left( \frac{n_z^e}{\sqrt{{n_x^e}^2+{n_y^e}^2}} \right)</math>

The rightmost expression is best suited for computer program implementation.<ref name=Gade/>

Longitude is found using:

:<math>\mathrm{longitude}=\arctan\left(\frac{n_y^e}{n_x^e} \right)</math>

In these expressions <math>\arctan(y/x)</math> should be implemented using a call to [atan2](/source/atan2)(''y'',''x'').  The [Pole](/source/Geographical_pole) [singularity](/source/Mathematical_singularity) of longitude is evident as [atan2](/source/atan2)(0,0) is undefined. Note that the equations are exact both for spherical and ellipsoidal Earth model.

== Example 1: Great circle distance==
Finding the [great circle distance](/source/great_circle_distance) between two horizontal positions (assuming spherical Earth) is usually done by means of latitude and longitude. [Three different expressions](/source/great_circle_distance) for this distance are common; the first is based on [arccos](/source/Inverse_trigonometric_function), the second is based on [arcsin](/source/Inverse_trigonometric_function), and the final is based on [arctan](/source/Inverse_trigonometric_function). The expressions, which are successively more complex to avoid [numerical instabilities](/source/Numerical_stability), are not easy to find, and since they are based on latitude and longitude, the Pole singularities may become a problem. They also contain [deltas](/source/Delta_(letter)) of latitude and longitude, which in general should be used with care near the ±[180° meridian](/source/180th_meridian) and the Poles.

Solving the same problem using ''n''-vector is simpler due to the possibility of using [vector algebra](/source/Vector_calculus). The arccos expression is achieved from the [dot product](/source/dot_product), while the [magnitude](/source/Magnitude_(mathematics)) of the [cross product](/source/cross_product) gives the arcsin expression. Combining the two gives the arctan expression:<ref name=Gade/>

:<math>\begin{align}
 & \Delta \sigma=\arccos\left( \mathbf n_a\cdot \mathbf n_b \right) \\ 
 & \Delta \sigma=\arcsin\left( \left| \mathbf n_a\times \mathbf n_b \right| \right) \\ 
 & \Delta \sigma=\arctan\left( \frac{\left| \mathbf n_a\times \mathbf n_b \right|}{\mathbf n_a\cdot \mathbf n_b} \right) \\ 
\end{align}</math>

where <math>\mathbf n_a</math> and <math>\mathbf n_b</math> are the ''n''-vectors representing the two positions ''a'' and ''b''. <math>\Delta\sigma</math> is the angular difference, and thus the great-circle distance is achieved by multiplying with the Earth radius. This expression also works at the poles and at the ±180° meridian. 

==Additional examples==
''n''-vector is also well-suited for common calculations such as:
* Interpolated position
* Mean/center position (midpoint of multiple positions)
* Weighted average position (e.g. of geographic data points)
* Intersection of two paths
* Cross track distance (cross track error)
* Along track distance
* Euclidean distance
* Triangulated position
* Absolute plus delta position (delta position may be azimuth & distance)
* Difference between absolute positions
* The first and second (direct/inverse) geodetic problems
* Find north and east directions
* Find horizontal and vertical components of a vector
Equations and code for these calculations can be found in the external links below or reference<ref name=Gade/>. The calculations will work equally well over long distances, and for any global positions. 

==See also==
*[Earth section paths](/source/Earth_section_paths)
*[Horizontal position representation](/source/Horizontal_position_representation)
*[Latitude](/source/Latitude)
*[Longitude](/source/Longitude)
*[Universal Transverse Mercator coordinate system](/source/Universal_Transverse_Mercator_coordinate_system)
*[Quaternion](/source/Quaternion)

==References==
{{Reflist}}

==External links==
* [https://www.navlab.net/nvector/ Solving 10 problems by means of the ''n''-vector]
* [https://github.com/topics/n-vector/ ''n''-vector libraries on GitHub in Python, C++, Java, C#, and most other languages]

Category:Navigation
Category:Geodesy
Category:Geographic position
Category:Geographic coordinate systems
Category:Ellipsoids

---
Adapted from the Wikipedia article [N-vector](https://en.wikipedia.org/wiki/N-vector) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/N-vector?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
