Advertisement Jump to content
Ilici

Simple Moon Position Calculation

This topic is 421 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know of any very simple moon position calculator? currently I'm using the algorithm from Computing Planetary Positions which I found on vterrain.org. The code I got is:
	float m = JulianDay / 12; //month, approximation
	float d = 367 * 2000 - 7 * ( 2000 + (m / 12 + 9) / 12 ) / 4 + 275 * m/9 + JulianDay - 730530;
	d = d + (TimeOfDay / 3600.0f) / 24.0;

	float N = (125.1228 - 0.0529538083 * d) / 180 * PI;
	float i = 5.1454;
	float w = (318.0634 + 0.1643573223 * d) / 180 * PI;
    float e = 0.054900; //eccentricity
    float M = (115.3654 + 13.0649929509 * d) / 180.0f * PI ; //mean anomaly

    float E = M + e * sin(M) * ( 1.0 + e * cos(M) );
	E = E - ( E - e * sin(E) - M ) / ( 1 - e * cos(E) );

    float xv = ( cos(E) - e );
    float yv = ( sqrt(1.0 - e*e) * sin(E) );

    float v = atan2( yv, xv );

    float xh = ( cos(N) * cos(v+w) - sin(N) * sin(v+w) * cos(i) );
    float yh = ( sin(N) * cos(v+w) + cos(N) * sin(v+w) * cos(i) );
    float zh = ( sin(v+w) * sin(i) );

    MoonPhi = atan2( yh, xh ); //longitude
    MoonTheta = atan2( zh, sqrt(xh*xh+yh*yh) ); //latitude

I'm not sure whether this is very correct, the moon does seem to move nicely and continuously but I don't know if the position in the sky is correct.

Share this post


Link to post
Share on other sites
Advertisement
Check:
http://www.stargazing.net/kepler/moon.html
http://njsas.org/projects/tidal_forces/altaz/pausch/ppcomp.html

Share this post


Link to post
Share on other sites

haha, I used a moon rotation function similar to the one you used.  It moved elliptically which was neat, but I ended up opting for a simple circle rotation to save those few extra processing steps.

Share this post


Link to post
Share on other sites

This topic is 421 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!