# Coordinate systems

Back to PastelMath

A coordinate system in ${\mathbb{R}}^{n}$ is a function $f : S \subset {\mathbb{R}}^{n} \to {\mathbb{R}}^{n}$ such that the restriction of $f$ to some cofinite set is a homeomorphism.

## Theory

Some commonly used coordinate systems include:

### Cartesian ${\mathbb{R}}^{n}$

${f}_{\textrm{c a r t e s i a n}} : {\mathbb{R}}^{n} \to {\mathbb{R}}^{n} : {f}_{\textrm{c a r t e s i a n}} \left({x}_{1} , \ldots , {x}_{n}\right) = \left(\begin{matrix}{x}_{1} \\ \setminus \vdots \\ {x}_{n}\end{matrix}\right)$

${f}_{\textrm{c a r t e s i a n}}^{-} 1 : {\mathbb{R}}^{n} \to {\mathbb{R}}^{n} : {f}_{\textrm{c a r t e s i a n}}^{-} 1 \left({x}_{1} , \ldots , {x}_{n}\right) = \left(\begin{matrix}{x}_{1} \\ \setminus \vdots \\ {x}_{n}\end{matrix}\right)$

### Spherical ${\mathbb{R}}^{n}$

The polar and spherical coordinate systems are simply special cases of the spherical coordinate system in ${\mathbb{R}}^{n}$:

Spherical coordinate systems are only defined for $n \ge 2$. To see where the spherical coordinate system gets its name, notice that $| {f}_{\textrm{h y p e r s p h e r i c a l}} \left(r , {\alpha}_{1} , \setminus \cdots , {\alpha}_{n - 1}\right) | = r$, where the norm is Euclidean.

### Generalized cylinder ${\mathbb{R}}^{n}$

All of the mentioned coordinate systems can be united under a single generalization. This is done by computing spherical coordinates only for the $k \le n$ first components of $v \in {\mathbb{R}}^{n}$, and leaving the other $n - k$ components as they were. This is called the generalized cylinder coordinate system. The spherical coordinate system is obtained by setting $k = n$. The cylinder coordinate system is obtained by setting $k = n - 1$. The Cartesian coordinate system is obtained by setting $k = 0$ (this is of course interesting only theoretically, since for $k = 0$, the conversion is just the identity function).

## Practice

Pastel implements coordinate conversions so that the Cartesian coordinate system is thought of as the most natural coordinate system. For all other coordinate system Pastel offers functions to convert to Cartesian coordinates and back. This way, if there are $n$ coordinate systems, only $O \left(n\right)$ conversion functions are needed instead of $O \left({n}^{2}\right)$ for conversions between all systems. Pastel offers conversion functions for the generalized cylinder coordinate system, as well as specialized functions for spherical and cylinder coordinate systems.