T
Tom Dacon
I'm curious to see if anyone has an opinion on this little design question -
I'm doing a computational astronomy library in C#, purely for my own use,
and one of the things that happens regularly is conversion of coordinates
from one frame of reference to another: spherical coordinates in the
ecliptic frame of reference, spherical coordinates in the equatorial frame
of reference, 3D rectangular coordinates in either, galactic coordinates,
horizontal coordinates, and on and on. The question relates to where to site
the conversion methods most naturally.
To illustrate the question, I've boiled it down to a simple case:
Consider 2D plane coordinates: you have Cartesian (rectangular) coordinates
(X and Y) and polar coordinates (angle and radius vector). The
transformations between them are well-known and simple. So you can take
rectangular coordinates (a subclass of Point, perhaps, named
CartesianCoords), apply the transformation to X and Y, and get out polar
coordinates. And vice versa.
So where do the conversion methods best reside? Here are some
possibilities:
1. A static conversion function such as CartesianToPolar(CartesianCoords cc)
returning a PolarCoordinates object;
2. An instance method on a CartesianCoords object returning a
PolarCoordinates object;
3. A PolarCoordinates constructor taking a CartesianCoords object, which
applies the conversion and populates its data members from the outcome of
the transformation.
Admittedly this is a fairly minor point, for the example above, but when you
have a half-dozen different coordinate systems, with potential conversions
between all pairs, there's a combinatorial explosion that might get ugly.
Also, while the transformation described above needs no other information
besides the coordinates, some of the astronomical transformations require
additional parameters.
Any thoughts?
Or if you don't think this is the right place to post a question like this,
how about a suggestion for a more appropriate newsgroup or site (I didn't
find a real natural venue in a quick search of the newsgroup names)?
Thanks,
Tom Dacon
Dacon Software Consulting
I'm doing a computational astronomy library in C#, purely for my own use,
and one of the things that happens regularly is conversion of coordinates
from one frame of reference to another: spherical coordinates in the
ecliptic frame of reference, spherical coordinates in the equatorial frame
of reference, 3D rectangular coordinates in either, galactic coordinates,
horizontal coordinates, and on and on. The question relates to where to site
the conversion methods most naturally.
To illustrate the question, I've boiled it down to a simple case:
Consider 2D plane coordinates: you have Cartesian (rectangular) coordinates
(X and Y) and polar coordinates (angle and radius vector). The
transformations between them are well-known and simple. So you can take
rectangular coordinates (a subclass of Point, perhaps, named
CartesianCoords), apply the transformation to X and Y, and get out polar
coordinates. And vice versa.
So where do the conversion methods best reside? Here are some
possibilities:
1. A static conversion function such as CartesianToPolar(CartesianCoords cc)
returning a PolarCoordinates object;
2. An instance method on a CartesianCoords object returning a
PolarCoordinates object;
3. A PolarCoordinates constructor taking a CartesianCoords object, which
applies the conversion and populates its data members from the outcome of
the transformation.
Admittedly this is a fairly minor point, for the example above, but when you
have a half-dozen different coordinate systems, with potential conversions
between all pairs, there's a combinatorial explosion that might get ugly.
Also, while the transformation described above needs no other information
besides the coordinates, some of the astronomical transformations require
additional parameters.
Any thoughts?
Or if you don't think this is the right place to post a question like this,
how about a suggestion for a more appropriate newsgroup or site (I didn't
find a real natural venue in a quick search of the newsgroup names)?
Thanks,
Tom Dacon
Dacon Software Consulting