Converting between Celestial Coordinate Systems

We begin by examining how to convert between two celestial coordinate systems represented by SkyFrames, as this is both an illuminating and practical example. Consider the problem of converting celestial coordinates between:

  1. The old FK4 system, with no E terms, a Besselian epoch of 1958.0 and a Besselian equinox of 1960.0.

  2. An ecliptic coordinate system based on the mean equinox and ecliptic of Julian epoch 2010.5.

This example is arbitrary but not completely unrealistic. Unless you already have expertise with such conversions, you are unlikely to find it straightforward.

Using AST, we begin by creating two SkyFrames to represent these coordinate systems, as follows:


\begin{terminalv}
...

Note how specifying the coordinate systems consists simply of initialising the attributes of each SkyFrameSkyFrame appropriately. The next step is to find a way of converting between these SkyFrames. This is done using astConvertastConvert, as follows:


\begin{terminalv}
AstFrameSet *cvt;
\par
...
\par
cvt = astConvert( skyframe1, s...
...conversion is not possible>
} else {
<conversion is possible>
}
\end{terminalv}

The third argument of astConvert is not used here and should be an empty string.

astConvert will return a null result, AST__NULL (as defined in the “ast.h” header file), if conversion is not possible. In this example, conversion is possible, so it will return a pointer to a new ObjectObject that describes the conversion.

The Object returned is called a FrameSetFrameSet. We have not discussed FrameSets yet (§13), but for the present purposes we can consider them simply as Objects that can behave both as Mappings and as Frames. It is the FrameSet's behaviour as a MappingMapping in which we are mainly interested here, because the Mapping it implements is the one we require—i.e. it converts between the two celestial coordinate systems (§14.1).

For example, if “alpha1” and “delta1” are two arrays containing the longitude and latitude, in radians, of N points on the sky in the original coordinate system (corresponding to “skyframe1”), then they could be converted into the new coordinate system (represented by “skyframe2”) as follows:


\begin{terminalv}
...

The new coordinates are returned via the “alpha2” and “delta2” arrays. To transform coordinates in the opposite direction, we simply invert the 5th (boolean int) argument to astTran2astTran2, as follows:


\begin{terminalv}
astTran2( cvt, N, alpha2, delta2, 0, alpha1, delta1 );
\end{terminalv}

The FrameSet returned by astConvert also contains information about the SkyFrames used in the conversion (§14.1). As we mentioned above, a FrameSet may be used as a FrameFrame and in this case it behaves like the “destination” Frame used in the conversion (i.e. like “skyframe2”). We could therefore use the “cvt” FrameSet to calculate the distance between two points (with coordinates in radians) in the destination coordinate system, using astDistanceastDistance:


\begin{terminalv}
double distance, point1[ 2 ], point2[ 2 ];
\par
...
\par
distance = astDistance( cvt, point1, point2 );
\end{terminalv}

and the result would be the same as if the “skyframe2” SkyFrame had been used.

Another way to see how the FrameSet produced by astConvert retains information about the coordinate systems involved is to set its ReportReport attribute (inherited from the Mapping class) so that it displays the coordinates before and after conversion (§4.8):


\begin{terminalv}
astSet( cvt, ''Report=1'' );
astTran2( cvt, N, alpha1, delta1, 1, alpha2, delta2 );
\end{terminalv}

The output from this might look like the following:


\begin{terminalv}
(2:06:03.0, 34:22:39) --> (42.1087, 20.2717)
(2:08:20.6, 35:31...
... (49.3695, 27.5311)
(2:26:40.6, 44:41:27) --> (50.2742, 28.4499)
\end{terminalv}

Here, we see that the input FK4 equatorial coordinate values (given in radians) have been formatted automatically in sexagesimal notation using the conventional hours for right ascension and degrees for declination. Conversely, the output ecliptic coordinates are shown in decimal degrees, as is conventional for ecliptic coordinates. Both are displayed using the default precision of 7 digits.[*]

In fact, the “cvt” FrameSet has access to all the information in the original SkyFrames which were passed to astConvert. If you had set a new Digits attribute value for either of these, the formatting above would reflect the different precision you requested by displaying a greater or smaller number of digits.