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×33 \times 3 orthogonal matrix R\mathbf{R}:

(xyz)=R(xyz)\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 xx-axis (R1R_1):

R1(θ)=(1000cosθsinθ0sinθcosθ)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 yy-axis (R2R_2):

R2(θ)=(cosθ0sinθ010sinθ0cosθ)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 zz-axis (R3R_3):

R3(θ)=(cosθsinθ0sinθcosθ0001)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 zz-axis carries the xx-axis toward the yy-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: R1=RT\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 xx-axis (the direction of γ\gamma). Therefore the transformation is a single rotation about xx.

Ecliptic to Equatorial #

(xeqyeqzeq)=R1(ε)(xeclyeclzecl)=(1000cosεsinε0sinεcosε)(xeclyeclzecl)\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δ=sinβcosε+cosβsinεsinλ\sin\delta = \sin\beta \cos\varepsilon + \cos\beta \sin\varepsilon \sin\lambda

tanα=sinλcosεtanβsinεcosλ\tan\alpha = \frac{\sin\lambda \cos\varepsilon - \tan\beta \sin\varepsilon}{\cos\lambda}

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

Equatorial to Ecliptic #

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

(xeclyeclzecl)=R1(ε)(xeqyeqzeq)=(1000cosεsinε0sinεcosε)(xeqyeqzeq)\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β=sinδcosεcosδsinεsinα\sin\beta = \sin\delta \cos\varepsilon - \cos\delta \sin\varepsilon \sin\alpha

tanλ=sinαcosε+tanδsinεcosα\tan\lambda = \frac{\sin\alpha \cos\varepsilon + \tan\delta \sin\varepsilon}{\cos\alpha}

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

Worked Example: Ecliptic to Equatorial #

Given: λ=197.83°\lambda = 197.83°, β=+1.25°\beta = +1.25°, ε=23.4393°\varepsilon = 23.4393°.

Step 1 — Convert to cartesian (ecliptic):

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

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

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

Step 2 — Apply R1(ε)R_1(-\varepsilon):

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

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

zeq=(0.30743)sin(23.4393°)+(0.02182)cos(23.4393°)=0.12224+0.02002=0.10222z_{\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):

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

δ=arcsin(0.10222)=5.87°\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=LSTα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 HH and declination δ\delta, the cartesian vector in the HA–Dec system is:

(xHAyHAzHA)=(cosδcosHcosδsinHsinδ)\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 yy: hour angle increases westward, while the standard cartesian convention has the yy-axis 90° east of the xx-axis. This convention places the xx-axis along the meridian (where H=0H = 0) and the zz-axis toward the NCP.

The horizontal system has the xx-axis toward the north point of the horizon, the yy-axis toward the east point, and the zz-axis toward the zenith. The transformation is a rotation about the yy-axis by the angle (90°ϕ)(90° - \phi):

(xhoryhorzhor)=(sinϕ0cosϕ010cosϕ0sinϕ)(xHAyHAzHA)\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:

sinh=sinϕsinδ+cosϕcosδcosH\sin h = \sin\phi \sin\delta + \cos\phi \cos\delta \cos H

tanA=cosδsinHsinδcosϕcosδsinϕcosH\tan A = \frac{-\cos\delta \sin H}{\sin\delta \cos\phi - \cos\delta \sin\phi \cos H}

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

Horizontal to Equatorial #

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

sinδ=sinϕsinh+cosϕcoshcosA\sin\delta = \sin\phi \sin h + \cos\phi \cos h \cos A

tanH=coshsinAsinhcosϕcoshsinϕcosA\tan H = \frac{-\cos h \sin A}{\sin h \cos\phi - \cos h \sin\phi \cos A}

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

Rising and Setting #

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

0=sinϕsinδ+cosϕcosδcosH00 = \sin\phi \sin\delta + \cos\phi \cos\delta \cos H_0

cosH0=tanϕtanδ\cos H_0 = -\tan\phi \tan\delta

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

The formula has three cases:

  • cosH01|\cos H_0| \leq 1: the object rises and sets normally.
  • cosH0<1\cos H_0 < -1 (i.e., tanϕtanδ>1\tan\phi \tan\delta > 1): the object is circumpolar (never sets).
  • cosH0>1\cos H_0 > 1 (i.e., tanϕtanδ<1\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=0h = 0 with h=h0h = h_0 where h0h_0 accounts for these effects (typically h0=0°50h_0 = -0°50' for the Sun, h0+0°125h_0 \approx +0°125' for the Moon). This modifies the formula to:

cosH0=sinh0sinϕsinδcosϕcosδ\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 aa, bb, cc and three angles AA, BB, CC 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) #

cosa=cosbcosc+sinbsinccosA\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) #

cosA=cosBcosC+sinBsinCcosa\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 #

sinasinA=sinbsinB=sincsinC\frac{\sin a}{\sin A} = \frac{\sin b}{\sin B} = \frac{\sin c}{\sin C}

Analogue Formula #

sinacosB=cosbsincsinbcosccosA\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 atan2\text{atan2}).

Five-Parts (Napier’s) Formula #

sinacosB=cosbsincsinbcosccosA\sin a \cos B = \cos b \sin c - \sin b \cos c \cos A

sinbcosA=cosasincsinacosccosB\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 cc. 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°ϕ90° - \phi (co-latitude)
Side PS Angular distance from pole to object 90°δ90° - \delta (co-declination)
Side ZS Angular distance from zenith to object 90°h90° - h (zenith distance)
Angle at P Angle at the pole, between PZ and PS HH (hour angle)
Angle at Z Angle at the zenith, between ZP and ZS 360°A360° - A (or AA, depending on convention)
Angle at S Angle at the object Parallactic angle qq

Applying the spherical law of cosines for side ZS:

cos(90°h)=cos(90°ϕ)cos(90°δ)+sin(90°ϕ)sin(90°δ)cosH\cos(90° - h) = \cos(90° - \phi)\cos(90° - \delta) + \sin(90° - \phi)\sin(90° - \delta)\cos H

which simplifies to:

sinh=sinϕsinδ+cosϕcosδcosH\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 qq 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).

tanq=sinHtanϕcosδsinδcosH\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 atan2\text{atan2} for the longitude-type coordinate and arcsin\arcsin for the latitude-type coordinate.

From → To Rotation axis Angle Key parameter
Ecliptic → Equatorial xx (γ\gamma direction) ε-\varepsilon Obliquity
Equatorial → Ecliptic xx (γ\gamma direction) +ε+\varepsilon Obliquity
Equatorial → Horizontal yy (east) 90°ϕ90° - \phi Latitude, LST
Horizontal → Equatorial yy (east) (90°ϕ)-(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 (λ1,β1)(\lambda_1, \beta_1) and (λ2,β2)(\lambda_2, \beta_2) in any coordinate system, the angular distance dd between them is:

cosd=sinβ1sinβ2+cosβ1cosβ2cos(λ2λ1)\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:

tand=(cosβ2sinΔλ)2+(cosβ1sinβ2sinβ1cosβ2cosΔλ)2sinβ1sinβ2+cosβ1cosβ2cosΔλ\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 Δλ=λ2λ1\Delta\lambda = \lambda_2 - \lambda_1. Use atan2\text{atan2} to evaluate dd 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 (δ±90°\delta \to \pm 90°), right ascension becomes ill-defined (the meridians converge). Near the zenith (h90°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 (λ=0,β=0\lambda = 0, \beta = 0) should transform to (α=0,δ=0\alpha = 0, \delta = 0). The summer solstice (λ=90°,β=0\lambda = 90°, \beta = 0) should give δ=+ε\delta = +\varepsilon, α=6h\alpha = 6^h. A point on the ecliptic at λ=180°\lambda = 180° should give δ=0\delta = 0, α=12h\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 16, 2026

Related Articles

Powered by Kerykeion and the Astrology API