Page 1 of 1

Nebula texture and Ra Dec conversion into xyz

Posted: 08.03.2003, 01:20
by Calculus
This is a question for Grant or Chris, but anyone can help me.
I'm in the process of making some textures for Deep Sky objects (like the M31 you can see in my gallery).
The problem I have is to convert a (Ra, Dec) into a xyz vector that celestia uses. I suppose the origin at Sol center but I get confuse with the sine and cosine functions and the 23.45 degrees of the ecliptic plan.
can someone give me the f g h transformation functions:
x=f(Ra,Dec)
y=g(Ra,Dec)
z=h(Ra,Dec)
Thanks

Posted: 08.03.2003, 02:07
by selden
Paul,

Well, I'm neither of them, but here's the formula used internally by Celestia (see http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/celestia/celestia/src/celengine/astro.cpp?rev=1.9&content-type=text/vnd.viewcvs-markup)

Code: Select all

 
// Convert equatorial coordinates to Cartesian celestial (or ecliptical)
// coordinates.
Point3d astro::equatorialToCelestialCart(double ra, double dec, double distance)
{
  double theta = ra / 24.0 * PI * 2 + PI;
    double phi = (dec / 90.0 - 1.0) * PI / 2;
    double x = cos(theta) * sin(phi) * distance;
    double y = cos(phi) * distance;
    double z = -sin(theta) * sin(phi) * distance;

    return (Point3d(x, y, z) * equatorialToCelestiald);
}




Earlier in this file is this definition:

Code: Select all

static Mat3d equatorialToCelestiald = Mat3d::xrotation(degToRad(23.4392911));

The matrix multiplication in the last line of equatorialToCelestialCart does the rotation from equatorial to ecliptic coordinates.

The xrotation operation is defined in http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/celestia/celestia/src/celmath/vecmath.h?rev=1.1&content-type=text/vnd.viewcvs-markup to be

Code: Select all

template<class T> Matrix3<T> Matrix3<T>::xrotation(T angle)
{
    T c = (T) cos(angle);
    T s = (T) sin(angle);

    return Matrix3<T>(Vector3<T>(1, 0, 0),
                      Vector3<T>(0, c, -s),
                      Vector3<T>(0, s, c));
}


Added later:
Here's the code fragment used to do the conversion for DSC objects, which is in http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/celestia/celestia/src/celengine/deepskyobj.cpp?rev=1.4&sortby=date&content-type=text/vnd.viewcvs-markup:

Code: Select all

    // Get position
    Vec3d position(0.0, 0.0, 0.0);
    if (params->getVector("Position", position))
    {
        setPosition(Point3d(position.x, position.y, position.z));
    }
    else
    {
        double distance = 1.0;
        double RA = 0.0;
        double dec = 0.0;
        params->getNumber("Distance", distance);
        params->getNumber("RA", RA);
        params->getNumber("Dec", dec);
        Point3d p = astro::equatorialToCelestialCart(RA, dec, distance);
        setPosition(p);
    }


Added yet later:
And here's the coordinate transform statement used when reading in the stars database in http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/celestia/celestia/src/celengine/stardb.cpp?rev=1.16&content-type=text/vnd.viewcvs-markup.

Code: Select all

    // Convert ra from degrees to hours for eqToCelCart function
    ra /= 15.0;
    star->setPosition(astro::equatorialToCelestialCart((float) ra, (float) dec, (float) distance));


Does this help?

[p.s. I edited this umptyump times, so you may have seen it in some intermediate state with different wording and critical pieces wrong or missing. I'm stopping now.]

Posted: 08.03.2003, 03:12
by Calculus
Thanks Selden,
the first part was easy.
Now I have to figure out this equation:

static Mat3d equatorialToCelestiald = Mat3d::xrotation(degToRad(23.4392911));

do you think it is a rotation only around the x axis ? or is there more ?

Posted: 08.03.2003, 03:36
by selden
Paul,

Yes, my understanding is that, by definition, the tilt of the earth's axis is strictly a rotaion about the "x" axis.

To put it another way:

Code: Select all

        x =  x0
        y =     y0*cos(angle) - z0*sin(angle)
        z =     y0*sin(angle) + z0*cos(angle)

Posted: 08.03.2003, 04:06
by Calculus
Thanks Selden. I now have all I was looking for. In a couple days I'll post images of Celestial Phenomena involving deep sky objects.