Next: Implementing New CoordTransform Classes Up: Converting Between Multiple Coordinate Previous: Basic Use

### Use Outside of a `CoordinateSystem`

It is perfectly legal to use a `CoordTransform` object directly to tranform positions without having to attach it to a `CoordinateSystem`. In this case, one would use one of the following `CoordTransform` methods:

`
- forward(double[] position)
- forward(double[] position, int[] axisIndexList)
- reverse(double[] position)
- reverse(double[] position, int[] axisIndexList)
`

Obviously, the `forward()` methods perform the forward transform. Normally, one would need to use the two-argument version to indicate how the transform is to be applied. In this case, the Axis Index List (described in §3.3.1) is given as a simple integer array, where the first element indicates which element in the position array is for the first axis as defined by the transform. As illustrated in the previous section, one would need to provide an Axis Index List for the `CelToGalCoordTransform` to indicate which axes are the right ascension and declination. By contrast, the `AbsToRelCoordTransform` will by default try to transform as many axes as it can in the order that they appear; in this case, one can use the one-argument versions of `forward()` and `reverse()`.

When you use the transforming methods directly, you may need to be prepared to catch two possible `CoordTransformException`s: `PositionBeyondDomainException` and
[4] `TransformUndefinedException`. One of these exceptions may be thrown if there is no logical or mathematical tranform for the input position. For example, the `LinToSphLinCoordTransform` class is used to project a flat surface onto a sphere using one of a variety of projection scheme (e.g. mercatur, sinusoidal, etc.). With certain projections, not all positions in the ``map'' plane correspond to positions on a globe; these positions would throw a
[4] `PositionBeyondDomainException`.

There are a few thing that you should note when using the transforming methods directly. First, in the interest of speed and efficiency, the transforming method has the option of overwriting the values within the input array. They also have the option of creating and returning a new array to hold the tranformed position. Therefore, after calling either `forward()` or `reverse()`, always assume that the input position has been corrupted and that the output position has the value you want. A good way to implement this tip would be with the following code:

    double pos = { 1.0, 234.25, 18.5 };
    pos = conversion.forward(pos);

The second thing to keep in mind is that the number of input axes need not equal the number of output axes (here would be a case where the transform would have to create a new array to hold the output position). Unless you know at programming time what the effect of the transform is, you should check the length of the output array before accessing the output position values.

Next: Implementing New CoordTransform Classes Up: Converting Between Multiple Coordinate Previous: Basic Use