0

我需要找出月球经度值以找到 Nakshatra 和tithi。

我使用下面的c语言代码来获取月球经度,

 //Longitude of Moon
    static double moon_long(double d)
    {
    double N, i, w, a, e, M, E, Et, x, y, r, v, xec, yec, zec, D, F, tmp, tmp1, tmp2, lon;

    N = 125.1228-0.0529538083*d;
    i = 5.1454;
    w = REV(318.0634+0.1643573223*d);
    a = 60.2666;
    e = 0.054900;
    M = REV(115.3654+13.0649929509*d);
    Mm = M;
    Lm = N+w+M;

    //Calculate Eccentricity anamoly
    tmp = M*D2R;
    E = M+R2D*e*sin(tmp)*(1+e*cos(tmp));

    tmp = E*D2R;
    Et = E-(E-R2D*e*sin(tmp)-M)/(1-e*cos(tmp));

    do {
        E = Et;
        tmp = E*D2R;
        Et = E-(E-R2D*e*sin(tmp)-M)/(1-e*cos(tmp));
    } while(E-Et>0.005);

    tmp = E*D2R;
    x = a*(cos(tmp)-e);
    y = a*sqrt(1-e*e)*sin(tmp);

    r = sqrt(x*x + y*y);
    v = REV(R2D*atan2(y,x));

    tmp = D2R*N;
    tmp1 = D2R*(v+w);
    tmp2 = D2R*i;
    xec = r*(cos(tmp)*cos(tmp1)-sin(tmp)*sin(tmp1)*cos(tmp2));
    yec = r*(sin(tmp)*cos(tmp1)+cos(tmp)*sin(tmp1)*cos(tmp2));
    zec = r*sin(tmp1)*sin(tmp2);

    //Do some corrections
    D = Lm - Ls;
    F = Lm - N;

    lon = R2D*atan2(yec,xec);

    lon+= -1.274*sin((Mm-2*D)*D2R);
    lon+= +0.658*sin((2*D)*D2R);
    lon+= -0.186*sin((Ms)*D2R);
    lon+= -0.059*sin((2*Mm-2*D)*D2R);
    lon+= -0.057*sin((Mm-2*D+Ms)*D2R);
    lon+= +0.053*sin((Mm+2*D)*D2R);
    lon+= +0.046*sin((2*D-Ms)*D2R);
    lon+= +0.041*sin((Mm-Ms)*D2R);
    lon+= -0.035*sin((D)*D2R);
    lon+= -0.031*sin((Mm+Ms)*D2R);
    lon+= -0.015*sin((2*F-2*D)*D2R);
    lon+= +0.011*sin((Mm-4*D)*D2R);

    return REV(lon);
}

但我得到了错误的值,请你解释一下,如何计算月球经度或我应该使用哪个程序。

4

1 回答 1

0

It is hard to tell you "what is wrong" since you are not answering some of the questions asked in the comments. Using one of the lines of your code, I found an implementation of what I think you are after at https://github.com/santhoshn/panchanga

I built the code (moving everything into its own directory, then compiling with

gcc *.c -lm -o panchanga

And tested it using today's date, and the time zone of Mumbai, India:

panchanga -d 26/09/2013 -t 20:02 -z +5:30

Output:

Tithi     : Saptami, Krishna Paksha
Nakshatra : Mrigashira
Yoga      : Vyatipata
Karana    : Bava
Rashi     : Mithuna

I don't know what these mean, but I confirmed the results against http://www.drikpanchang.com/?l=10455 - and they agreed.

My advice to you: see how this solution differs from what you are doing - that's how you will find "what is wrong with your code".

于 2013-09-26T14:35:37.730 回答