/// <summary> /// Converting body's heliocentric coordinates into body's geocentric coordinates /// This method works only for Mars, Mercury, Jupiter, Venus and Saturn /// Other planets have their coordinates calculated in geocentric coordinate system already /// </summary> /// <param name="bodyId">ID of the celestial body</param> private void ConvertHeliocentricToGeocentric(int bodyId) { if (bodyId <= 1 || bodyId >= 7) { return; } for (int i = 0; i < PAGE_ITEMS; i++) { double longitudalDifference = data[bodyId, i, 0] - data[0, i, 0] - 180; double geocentricLongitude = data[bodyId, i, 0] + GCMath.arcTan2Deg(GCMath.sinDeg(longitudalDifference), data[bodyId, i, 2] - GCMath.cosDeg(longitudalDifference)); double sx = data[0, i, 2] * GCMath.sinDeg(data[0, i, 0]); double sy = data[0, i, 2] * GCMath.cosDeg(data[0, i, 0]); double sz = data[0, i, 2] * GCMath.sinDeg(data[0, i, 1]); double sq = data[0, i, 2] * GCMath.cosDeg(data[0, i, 1]); double vx = data[bodyId, i, 2] * GCMath.sinDeg(data[bodyId, i, 0]); double vy = data[bodyId, i, 2] * GCMath.cosDeg(data[bodyId, i, 0]); double vz = data[bodyId, i, 2] * GCMath.sinDeg(data[bodyId, i, 1]); double vq = data[bodyId, i, 2] * GCMath.cosDeg(data[bodyId, i, 1]); data[bodyId, i, 0] = GCMath.putIn360(geocentricLongitude); //data[bodyId, i, 0] = GCMath.putIn360(GCMath.arcTan2Deg(sy + vy, sx + vx)); data[bodyId, i, 1] = GCMath.arcTan2Deg(sz + vz, sq + vq); data[bodyId, i, 2] = Math.Sqrt((sy + vy) * (sy + vy) + (sx + vx) * (sx + vx)); } }
/// <summary> /// Converting earth's heliocentric coordinates into sun's geocentric coordinates /// </summary> private void ConvertEarthToSun() { for (int i = 0; i < PAGE_ITEMS; i++) { data[0, i, 0] = GCMath.putIn360(data[0, i, 0] + 180.0); data[0, i, 1] = -data[0, i, 1]; } }
/// <summary> /// Calculates geocentric coordinates for celestial body /// </summary> /// <param name="julianDate"></param> /// <param name="L">Longitude in degrees (0deg to 360deg)</param> /// <param name="B">Latitude in degrees (-180deg to 180deg)</param> /// <param name="R">Radius in AU</param> public static void Calculate(double julianDate, out double L, out double B, out double R) { double t = (julianDate - 2451545) / 36525; double t2 = t * t; L = GCMath.putIn360(180 + 125.044555 - t * 1934.1361849 + t2 * 0.0020762 + t2 * t / 467410 - t2 * t2 / 60616000); B = 0.0; R = 0.3; }
/// <summary> /// /// </summary> /// <param name="bodyId">0 - sun, 1-moon, 2-mars, 3-mercury, 4-jupiter, 5-venus, 6-saturn, 7-rahu, 8-ketu, 9-ascendant</param> /// <param name="julianDate"></param> /// <param name="L">Longitude in degrees</param> /// <param name="B">Latitude in degrees</param> /// <param name="R">Radius in AU</param> public static void GetGeocentricCoordinates(int bodyId, double julianDate, out double L, out double B, out double R) { // for sun and moon calculate always fresh values if (bodyId == 0) { GCEarth.Calculate(julianDate, out L, out B, out R); L = GCMath.putIn360(L + 180); B = -B; return; } else if (bodyId == 1) { GCMoonData.Calculate(julianDate, out L, out B, out R); return; } else { GCAstronomyCoordPage page = null; int b = Convert.ToInt32(Math.Floor(julianDate)); int a = b / GCAstronomyCoordPage.PAGE_SIZE; int Base = a * GCAstronomyCoordPage.PAGE_SIZE; int Index = b - Base + GCAstronomyCoordPage.PAGE_HEAD; double fraction = julianDate - b; if (pages.ContainsKey(a)) { page = pages[a]; } else { page = new GCAstronomyCoordPage(Base); pages.Add(a, page); } if (!page.dataInit[bodyId]) { page.InitializePlanet(bodyId); } L = GCMath.putIn360(Interpolate(page.data[bodyId, Index - 2, 0], page.data[bodyId, Index - 1, 0], page.data[bodyId, Index, 0], page.data[bodyId, Index + 1, 0], page.data[bodyId, Index + 2, 0], fraction)); B = Interpolate(page.data[bodyId, Index - 2, 1], page.data[bodyId, Index - 1, 1], page.data[bodyId, Index, 1], page.data[bodyId, Index + 1, 1], page.data[bodyId, Index + 2, 1], fraction); R = Interpolate(page.data[bodyId, Index - 2, 2], page.data[bodyId, Index - 1, 2], page.data[bodyId, Index, 2], page.data[bodyId, Index + 1, 2], page.data[bodyId, Index + 2, 2], fraction); } }
public static double GetRawLongitude(int bodyId, int julianDay) { double L, B, R; // for sun and moon calculate always fresh values if (bodyId == 0) { GCEarth.Calculate(julianDay, out L, out B, out R); return(GCMath.putIn360(L + 180)); } else if (bodyId == 1) { GCMoonData.Calculate(julianDay, out L, out B, out R); return(L); } else { GCAstronomyCoordPage page = null; int b = julianDay; int a = b / GCAstronomyCoordPage.PAGE_SIZE; int Base = a * GCAstronomyCoordPage.PAGE_SIZE; int Index = b - Base + GCAstronomyCoordPage.PAGE_HEAD; if (pages.ContainsKey(a)) { page = pages[a]; } else { page = new GCAstronomyCoordPage(Base); pages.Add(a, page); } if (!page.dataInit[bodyId]) { page.InitializePlanet(bodyId); } return(page.data[bodyId, Index, 0]); } }