Try Astrologer API

Subscribe to support and grow the project.

Coordinate Transformations and Spherical Trigonometry #

The previous article defined four coordinate systems on the celestial sphere. This article develops the mathematics for converting between them: rotation matrices for systematic transformation of cartesian vectors, and spherical trigonometry for direct angular computation. Both methods give identical results; the choice is one of convenience.

Rotation Matrices #

A transformation between two coordinate systems that share the same origin (the center of the celestial sphere) is a rotation. In cartesian form, a rotation is a $3 \times 3$ orthogonal matrix $\mathbf{R}$:

$$ \begin{pmatrix} x’ \ y’ \ z’ \end{pmatrix} = \mathbf{R} \begin{pmatrix} x \ y \ z \end{pmatrix} $$

The three elementary rotations about the coordinate axes are:

Rotation by angle $\theta$ about the $x$-axis ($R_1$):

$$ R_1(\theta) = \begin{pmatrix} 1 & 0 & 0 \ 0 & \cos\theta & \sin\theta \ 0 & -\sin\theta & \cos\theta \end{pmatrix} $$

Rotation by angle $\theta$ about the $y$-axis ($R_2$):

$$ R_2(\theta) = \begin{pmatrix} \cos\theta & 0 & -\sin\theta \ 0 & 1 & 0 \ \sin\theta & 0 & \cos\theta \end{pmatrix} $$

Rotation by angle $\theta$ about the $z$-axis ($R_3$):

$$ R_3(\theta) = \begin{pmatrix} \cos\theta & \sin\theta & 0 \ -\sin\theta & \cos\theta & 0 \ 0 & 0 & 1 \end{pmatrix} $$

The sign convention here follows the “positive rotation” convention used in the Explanatory Supplement and by SOFA: a positive rotation about the $z$-axis carries the $x$-axis toward the $y$-axis. Different sources use different sign conventions for these matrices — always verify before combining formulas from multiple references.

The inverse of a rotation matrix is its transpose: $\mathbf{R}^{-1} = \mathbf{R}^T$. This is useful: to reverse a transformation, transpose the matrix.

Ecliptic ↔ Equatorial Transformation #

The ecliptic and equatorial systems share the same reference direction ($\gamma$, the vernal equinox) but differ in their fundamental planes. The ecliptic plane is tilted by the obliquity $\varepsilon$ relative to the equatorial plane, and the tilt axis is the $x$-axis (the direction of $\gamma$). Therefore the transformation is a single rotation about $x$.

Ecliptic to Equatorial #

$$ \begin{pmatrix} x_{\text{eq}} \ y_{\text{eq}} \ z_{\text{eq}} \end{pmatrix} = R_1(-\varepsilon) \begin{pmatrix} x_{\text{ecl}} \ y_{\text{ecl}} \ z_{\text{ecl}} \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 \ 0 & \cos\varepsilon & -\sin\varepsilon \ 0 & \sin\varepsilon & \cos\varepsilon \end{pmatrix} \begin{pmatrix} x_{\text{ecl}} \ y_{\text{ecl}} \ z_{\text{ecl}} \end{pmatrix} $$

In spherical coordinates, the component equations expand to the classical formulas:

$$ \sin\delta = \sin\beta \cos\varepsilon + \cos\beta \sin\varepsilon \sin\lambda $$

$$ \tan\alpha = \frac{\sin\lambda \cos\varepsilon - \tan\beta \sin\varepsilon}{\cos\lambda} $$

The $\alpha$ formula should be evaluated using $\text{atan2}$ on the numerator and denominator separately, not as a single $\arctan$, to resolve the quadrant.

Equatorial to Ecliptic #

The inverse transformation is the transpose (which, for a rotation about $x$, is the same rotation with $-\varepsilon$ replaced by $+\varepsilon$):

$$ \begin{pmatrix} x_{\text{ecl}} \ y_{\text{ecl}} \ z_{\text{ecl}} \end{pmatrix} = R_1(\varepsilon) \begin{pmatrix} x_{\text{eq}} \ y_{\text{eq}} \ z_{\text{eq}} \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 \ 0 & \cos\varepsilon & \sin\varepsilon \ 0 & -\sin\varepsilon & \cos\varepsilon \end{pmatrix} \begin{pmatrix} x_{\text{eq}} \ y_{\text{eq}} \ z_{\text{eq}} \end{pmatrix} $$

In spherical form:

$$ \sin\beta = \sin\delta \cos\varepsilon - \cos\delta \sin\varepsilon \sin\alpha $$

$$ \tan\lambda = \frac{\sin\alpha \cos\varepsilon + \tan\delta \sin\varepsilon}{\cos\alpha} $$

Again, use $\text{atan2}$ for $\lambda$.

Worked Example: Ecliptic to Equatorial #

Given: $\lambda = 197.83°$, $\beta = +1.25°$, $\varepsilon = 23.4393°$.

Step 1 — Convert to cartesian (ecliptic):

$$ x_{\text{ecl}} = \cos(1.25°)\cos(197.83°) = 0.99976 \times (-0.95148) = -0.95125 $$

$$ y_{\text{ecl}} = \cos(1.25°)\sin(197.83°) = 0.99976 \times (-0.30750) = -0.30743 $$

$$ z_{\text{ecl}} = \sin(1.25°) = 0.02182 $$

Step 2 — Apply $R_1(-\varepsilon)$:

$$ x_{\text{eq}} = -0.95125 $$

$$ y_{\text{eq}} = (-0.30743)\cos(23.4393°) - (0.02182)\sin(23.4393°) = -0.28208 - 0.00868 = -0.29076 $$

$$ z_{\text{eq}} = (-0.30743)\sin(23.4393°) + (0.02182)\cos(23.4393°) = -0.12224 + 0.02002 = -0.10222 $$

Step 3 — Convert back to spherical (equatorial):

$$ \alpha = \text{atan2}(-0.29076, -0.95125) = 197.00° = 13^h 08^m 00^s $$

$$ \delta = \arcsin(-0.10222) = -5.87° $$

Verification: the ecliptic longitude is near 198° (≈18° Libra), so the right ascension should be somewhat close but shifted. The declination is modestly south, consistent with a point slightly south of the ecliptic at that longitude.

Equatorial ↔ Horizontal Transformation #

The transformation between equatorial and horizontal coordinates is more complex because it involves two parameters that change with the observer: the geographic latitude $\phi$ and the local sidereal time (LST), which determines the hour angle $H = \text{LST} - \alpha$.

The transformation proceeds in two stages:

  1. Replace right ascension with hour angle (using LST).
  2. Rotate from the hour-angle/declination system to the azimuth/altitude system (using $\phi$).

Equatorial (Hour Angle) to Horizontal #

Starting from hour angle $H$ and declination $\delta$, the cartesian vector in the HA–Dec system is:

$$ \begin{pmatrix} x_{\text{HA}} \ y_{\text{HA}} \ z_{\text{HA}} \end{pmatrix} = \begin{pmatrix} \cos\delta \cos H \ -\cos\delta \sin H \ \sin\delta \end{pmatrix} $$

Note the negative sign on $y$: hour angle increases westward, while the standard cartesian convention has the $y$-axis 90° east of the $x$-axis. This convention places the $x$-axis along the meridian (where $H = 0$) and the $z$-axis toward the NCP.

The horizontal system has the $x$-axis toward the north point of the horizon, the $y$-axis toward the east point, and the $z$-axis toward the zenith. The transformation is a rotation about the $y$-axis by the angle $(90° - \phi)$:

$$ \begin{pmatrix} x_{\text{hor}} \ y_{\text{hor}} \ z_{\text{hor}} \end{pmatrix} = \begin{pmatrix} \sin\phi & 0 & -\cos\phi \ 0 & 1 & 0 \ \cos\phi & 0 & \sin\phi \end{pmatrix} \begin{pmatrix} x_{\text{HA}} \ y_{\text{HA}} \ z_{\text{HA}} \end{pmatrix} $$

Expanding and converting to spherical horizontal coordinates:

$$ \sin h = \sin\phi \sin\delta + \cos\phi \cos\delta \cos H $$

$$ \tan A = \frac{-\cos\delta \sin H}{\sin\delta \cos\phi - \cos\delta \sin\phi \cos H} $$

The altitude $h$ is obtained directly from the first equation via $\arcsin$. The azimuth $A$ is obtained from the second using $\text{atan2}$, then normalized to $[0°, 360°)$.

Horizontal to Equatorial #

The inverse transformation (transpose of the rotation matrix) gives:

$$ \sin\delta = \sin\phi \sin h + \cos\phi \cos h \cos A $$

$$ \tan H = \frac{-\cos h \sin A}{\sin h \cos\phi - \cos h \sin\phi \cos A} $$

Then $\alpha = \text{LST} - H$, normalized.

Rising and Setting #

An object rises or sets when its altitude $h = 0$. Setting $\sin h = 0$ in the altitude formula:

$$ 0 = \sin\phi \sin\delta + \cos\phi \cos\delta \cos H_0 $$

$$ \cos H_0 = -\tan\phi \tan\delta $$

This is the hour angle at rising/setting (ignoring atmospheric refraction). The object rises at $H = 360° - H_0$ (or equivalently $-H_0$) and sets at $H = H_0$.

The formula has three cases:

  • $|\cos H_0| \leq 1$: the object rises and sets normally.
  • $\cos H_0 < -1$ (i.e., $\tan\phi \tan\delta > 1$): the object is circumpolar (never sets).
  • $\cos H_0 > 1$ (i.e., $\tan\phi \tan\delta < -1$): the object never rises.

In practice, atmospheric refraction raises objects by about 34′ at the horizon, and the Sun and Moon have non-negligible angular diameters. For a more accurate rising/setting calculation, replace $h = 0$ with $h = h_0$ where $h_0$ accounts for these effects (typically $h_0 = -0°50’$ for the Sun, $h_0 \approx +0°125’$ for the Moon). This modifies the formula to:

$$ \cos H_0 = \frac{\sin h_0 - \sin\phi \sin\delta}{\cos\phi \cos\delta} $$

Spherical Trigonometry #

Spherical trigonometry provides an alternative (and often more direct) route to the same results. A spherical triangle is a figure on the sphere bounded by three arcs of great circles. Its three sides $a$, $b$, $c$ and three angles $A$, $B$, $C$ are all measured in angular units. Each side is the angular length of the corresponding arc; each angle is the dihedral angle between the planes of the two great circles meeting at that vertex.

Spherical Law of Cosines (for sides) #

$$ \cos a = \cos b \cos c + \sin b \sin c \cos A $$

This is the fundamental formula. It relates a side to the opposite angle and the other two sides. The planar law of cosines is the limiting case for small triangles.

Spherical Law of Cosines (for angles) #

$$ \cos A = -\cos B \cos C + \sin B \sin C \cos a $$

Note the minus sign, which has no planar analogue.

Spherical Law of Sines #

$$ \frac{\sin a}{\sin A} = \frac{\sin b}{\sin B} = \frac{\sin c}{\sin C} $$

Analogue Formula #

$$ \sin a \cos B = \cos b \sin c - \sin b \cos c \cos A $$

This combines elements of the cosine and sine laws and is useful when both the sine and cosine of an unknown angle are needed (enabling $\text{atan2}$).

Five-Parts (Napier’s) Formula #

$$ \sin a \cos B = \cos b \sin c - \sin b \cos c \cos A $$

$$ \sin b \cos A = \cos a \sin c - \sin a \cos c \cos B $$

These are the same analogue formulas, written for the two different angles adjacent to side $c$. They are called “five-parts” because each involves five of the six elements.

The Astronomical Triangle (PZS) #

The single most important spherical triangle in positional astronomy connects three points:

  • P — the north celestial pole
  • Z — the zenith
  • S — the celestial object (star, planet, etc.)

The sides and angles of this triangle encode the relationships between equatorial and horizontal coordinates:

Element Definition Value
Side PZ Angular distance from pole to zenith $90° - \phi$ (co-latitude)
Side PS Angular distance from pole to object $90° - \delta$ (co-declination)
Side ZS Angular distance from zenith to object $90° - h$ (zenith distance)
Angle at P Angle at the pole, between PZ and PS $H$ (hour angle)
Angle at Z Angle at the zenith, between ZP and ZS $360° - A$ (or $A$, depending on convention)
Angle at S Angle at the object Parallactic angle $q$

Applying the spherical law of cosines for side ZS:

$$ \cos(90° - h) = \cos(90° - \phi)\cos(90° - \delta) + \sin(90° - \phi)\sin(90° - \delta)\cos H $$

which simplifies to:

$$ \sin h = \sin\phi \sin\delta + \cos\phi \cos\delta \cos H $$

This is identical to the formula derived from the rotation matrix. Every equatorial–horizontal formula can be derived from the PZS triangle. The rotation-matrix approach and the spherical-trigonometry approach are two representations of the same geometry.

The Parallactic Angle #

The angle $q$ at vertex S (the object) is the parallactic angle. It measures the inclination of the great circle from the object to the pole, relative to the vertical. The parallactic angle appears in the computation of position angles and in atmospheric refraction corrections applied to coordinates (as opposed to altitude alone).

$$ \tan q = \frac{\sin H}{\tan\phi \cos\delta - \sin\delta \cos H} $$

Coordinate Transformation Summary #

The table below collects the key transformation formulas. In every case, use $\text{atan2}$ for the longitude-type coordinate and $\arcsin$ for the latitude-type coordinate.

From → To Rotation axis Angle Key parameter
Ecliptic → Equatorial $x$ ($\gamma$ direction) $-\varepsilon$ Obliquity
Equatorial → Ecliptic $x$ ($\gamma$ direction) $+\varepsilon$ Obliquity
Equatorial → Horizontal $y$ (east) $90° - \phi$ Latitude, LST
Horizontal → Equatorial $y$ (east) $-(90° - \phi)$ Latitude, LST

The ecliptic ↔ horizontal transformation has no single-step shortcut; it chains through equatorial coordinates. The ecliptic–equatorial step is time-independent (obliquity changes slowly). The equatorial–horizontal step is time-dependent (hour angle changes continuously with Earth’s rotation).

Angular Distance Between Two Points #

Given two points with spherical coordinates $(\lambda_1, \beta_1)$ and $(\lambda_2, \beta_2)$ in any coordinate system, the angular distance $d$ between them is:

$$ \cos d = \sin\beta_1 \sin\beta_2 + \cos\beta_1 \cos\beta_2 \cos(\lambda_2 - \lambda_1) $$

This is the spherical law of cosines applied to the triangle with one vertex at the pole.

For small separations (a few arcminutes or less), this formula suffers from numerical cancellation. The Vincenty formula is more robust:

$$ \tan d = \frac{\sqrt{(\cos\beta_2 \sin\Delta\lambda)^2 + (\cos\beta_1 \sin\beta_2 - \sin\beta_1 \cos\beta_2 \cos\Delta\lambda)^2}}{\sin\beta_1 \sin\beta_2 + \cos\beta_1 \cos\beta_2 \cos\Delta\lambda} $$

where $\Delta\lambda = \lambda_2 - \lambda_1$. Use $\text{atan2}$ to evaluate $d$ from the numerator and denominator.

For the specific case of aspect calculation in astrology, the relevant quantity is usually the difference in ecliptic longitude (not the true angular distance), because ecliptic latitude is ignored. This simplifies to the longitude-difference formula with wraparound handling from the previous article.

Implementation Notes #

  1. Precision of $\varepsilon$: for modern charts (say, 1800–2200 CE), using the IAU 2006 mean obliquity polynomial from The Celestial Sphere is sufficient for the ecliptic–equatorial transformation. For higher precision, add the nutation correction $\Delta\varepsilon$ to obtain the true obliquity; see Precession and Nutation.

  2. Which $\varepsilon$?: The mean obliquity ignores nutation; the true obliquity includes it. For computing apparent positions (matching what you see in the sky), use the true obliquity. For transforming mean catalog positions, use the mean obliquity. The distinction matters at the level of a few arcseconds.

  3. Matrix vs. direct formulas: For a single transformation, the direct spherical formulas are efficient. For chaining multiple transformations (ecliptic → equatorial → hour-angle → horizontal), multiply the rotation matrices first, then apply the product matrix to each object. This is faster when transforming many objects and avoids cumulative rounding.

  4. Polar regions: Near the celestial poles ($\delta \to \pm 90°$), right ascension becomes ill-defined (the meridians converge). Near the zenith ($h \to 90°$), azimuth becomes ill-defined. Software should detect these cases and handle them gracefully — typically by recognizing that the degenerate coordinate is meaningless rather than returning a wild value.

  5. Testing: Verify your implementation against known values. Useful test cases: the vernal equinox ($\lambda = 0, \beta = 0$) should transform to ($\alpha = 0, \delta = 0$). The summer solstice ($\lambda = 90°, \beta = 0$) should give $\delta = +\varepsilon$, $\alpha = 6^h$. A point on the ecliptic at $\lambda = 180°$ should give $\delta = 0$, $\alpha = 12^h$.

References #

  • Meeus, J. (1998). Astronomical Algorithms, 2nd ed. Willmann-Bell. Chapters 12–13.
  • Smart, W. M., & Green, R. M. (1977). Textbook on Spherical Astronomy, 6th ed. Cambridge University Press. Chapters 1–4.
  • Explanatory Supplement to the Astronomical Almanac, 3rd ed. (2013). University Science Books. Chapter 1.
  • Green, R. M. (1985). Spherical Astronomy. Cambridge University Press.

All articles are curated by Giacomo Battaglia and follow our editorial guidelines.

Last updated: August 14, 2026

Related Articles

Powered by Kerykeion and the Astrology API