private ulong GetDateTimeULong(string DateS) { // ShowStatus( " " ); // ShowStatus( "DateS: " + DateS ); // A.D. 2018-Jun-13 00:00:00.0000 DateS = DateS.Replace("A.D.", "").Trim(); string[] SplitS = DateS.Split(new Char[] { ' ' }); if (SplitS.Length < 2) { return(0); } string DatePart = SplitS[0].Trim(); string TimePart = SplitS[1].Trim(); // ShowStatus( "DatePart: " + DatePart ); // ShowStatus( "TimePart: " + TimePart ); // DatePart: 2018-Jun-13 SplitS = DatePart.Split(new Char[] { '-' }); int Year = GetIntegerValue(SplitS[0]); int Month = MonthNameToInt(SplitS[1]); int Day = GetIntegerValue(SplitS[2]); SplitS = TimePart.Split(new Char[] { ':' }); int Hour = GetIntegerValue(SplitS[0]); int Minute = GetIntegerValue(SplitS[1]); double SecondsD = GetDoubleValue(SplitS[2]); int Second = (int)Math.Truncate(SecondsD); // SecondsD -= Second; // SecondsD = SecondsD * 1000; int Millisecond = 0; // (int)Math.Truncate( SecondsD ); ECTime RecTime = new ECTime(); RecTime.SetUTCTime(Year, Month, Day, Hour, Minute, Second, Millisecond); // ShowStatus( RecTime.ToCrudeString()); // SetFromIndex( ulong Index ) return(RecTime.GetIndex()); }
internal void Copy(ECTime ToCopy) { // This won't be quite exact since it's to the // nearest millisecond. UTCTime = new DateTime(ToCopy.GetYear(), ToCopy.GetMonth(), ToCopy.GetDay(), ToCopy.GetHour(), ToCopy.GetMinute(), ToCopy.GetSecond(), ToCopy.GetMillisecond(), DateTimeKind.Utc); // DateTimeKind.Local }
internal SolarSystem(MainForm UseForm, Model3DGroup Use3DGroup) { MForm = UseForm; Main3DGroup = Use3DGroup; // The local time for the sun. SunTime = new ECTime(); SunTime.SetToNow(); // SpringTime = new ECTime(); // InitializeTimes(); SpaceObjectArray = new SpaceObject[2]; AddInitialSpaceObjects(); }
internal JPLRec GetNearestRecByDateTime(ulong ToMatch) { if (JPLRecArrayLast < 1) { JPLRec RecNone = new JPLRec(); RecNone.CalDate = 0; return(RecNone); } ECTime BigDate = new ECTime(); BigDate.SetToYear2099(); // Set NearestValue to be bigger than any // reasonable value. long NearestValue = (long)BigDate.GetIndex(); // This should be a binary search on sorted data. int NearestIndex = 0; for (int Count = 0; Count < JPLRecArrayLast; Count++) { JPLRec Rec = JPLRecArray[Count]; if (Rec.CalDate > ToMatch) { continue; } long Diff = (long)ToMatch - (long)Rec.CalDate; if (Diff < NearestValue) { NearestValue = Diff; NearestIndex = Count; } } if (NearestIndex > (JPLRecArrayLast - 10)) { MessageBox.Show("Need new data for: " + FileName, "Need Data", MessageBoxButtons.OK, MessageBoxIcon.Stop); } return(JPLRecArray[NearestIndex]); }
/* * private void InitializeTimes() * { * SunTime.SetToNow(); * * // https://en.wikipedia.org/wiki/March_equinox * * // "Spring Equinox 2018 was at 10:15 AM on * // March 20." * SpringTime.SetUTCTime( 2018, * 3, * 20, * 10, * 15, * 0, * 0 ); * * * } */ /* * private void SetPositionsAndTime( ECTime SetTime ) * { * SunTime.Copy( SetTime ); * * } */ private void AddInitialSpaceObjects() { try { // Sun: string JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLSun.txt"; Sun = new PlanetSphere(MForm, "Sun", true, JPLFileName); Sun.Radius = 695700 * ModelConstants.TenTo3; Sun.Mass = ModelConstants.MassOfSun; Sun.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\sun.jpg"; AddSpaceObject(Sun); // Earth: JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLEarth.txt"; Earth = new EarthGeoid(MForm, "Earth", JPLFileName); Earth.Mass = ModelConstants.MassOfEarth; Earth.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\earth.jpg"; AddSpaceObject(Earth); // Moon: JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLMoon.txt"; Moon = new PlanetSphere(MForm, "Moon", false, JPLFileName); // Radius: About 1,737.1 kilometers. Moon.Radius = 1737100; Moon.Mass = ModelConstants.MassOfMoon; Moon.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\moon.jpg"; AddSpaceObject(Moon); // Space Station: // Both Earth and the Space Station need to be // using the same time intervals for the JPL // data. // JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLSpaceStation.txt"; // SpaceStation = new PlanetSphere( MForm, "Space Station", false, JPLFileName ); // It's about 418 kilometers above the Earth. // SpaceStation.Radius = 400000; // 418000; // SpaceStation.Mass = 1.0; // SpaceStation.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\TestImage2.jpg"; // AddSpaceObject( SpaceStation ); /* * I would need to set this position after getting * Earth rotation angle and all that. * // Leadville marker: * JPLFileName = ""; * Leadville = new PlanetSphere( MForm, "Leadville", false, JPLFileName ); * Leadville.Radius = 1000000; * Leadville.Mass = 0; * Leadville.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\TestImage.jpg"; * AddSpaceObject( Leadville ); */ // Mercury: JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLMercury.txt"; PlanetSphere Mercury = new PlanetSphere( MForm, "Mercury", false, JPLFileName); Mercury.Radius = 2440000d * RadiusScale; Mercury.Mass = ModelConstants.MassOfMercury; Mercury.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\Mercury.jpg"; AddSpaceObject(Mercury); // Venus: JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLVenus.txt"; PlanetSphere Venus = new PlanetSphere( MForm, "Venus", false, JPLFileName); Venus.Radius = 6051000 * RadiusScale; // 6,051 km Venus.Mass = ModelConstants.MassOfVenus; Venus.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\Venus.jpg"; AddSpaceObject(Venus); // Mars: JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLMars.txt"; PlanetSphere Mars = new PlanetSphere( MForm, "Mars", false, JPLFileName); Mars.Radius = 3396000 * RadiusScale; Mars.Mass = ModelConstants.MassOfMars; Mars.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\mars.jpg"; AddSpaceObject(Mars); // Jupiter: JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLJupiter.txt"; PlanetSphere Jupiter = new PlanetSphere( MForm, "Jupiter", false, JPLFileName); // m t Jupiter.Radius = 69911000d * RadiusScale; // 69,911 km Jupiter.Mass = ModelConstants.MassOfJupiter; Jupiter.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\Jupiter.jpg"; AddSpaceObject(Jupiter); // Saturn: JPLFileName = "C:\\Eric\\ClimateModel\\EphemerisData\\JPLSaturn.txt"; PlanetSphere Saturn = new PlanetSphere( MForm, "Saturn", false, JPLFileName); // m t Saturn.Radius = 58232000d * RadiusScale; // 58,232 km Saturn.Mass = ModelConstants.MassOfSaturn; Saturn.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\Saturn.jpg"; AddSpaceObject(Saturn); // North Pole: PlanetSphere NorthPole = new PlanetSphere( MForm, "North Pole", false, ""); NorthPole.Radius = 400000d; NorthPole.Mass = 0; NorthPole.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\TestImage2.jpg"; AddSpaceObject(NorthPole); // Moon Axis: PlanetSphere MoonAxis = new PlanetSphere( MForm, "Moon Axis", false, ""); MoonAxis.Radius = 200000d; MoonAxis.Mass = 0; MoonAxis.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\TestImage2.jpg"; AddSpaceObject(MoonAxis); // Solar North: PlanetSphere SolarNorth = new PlanetSphere( MForm, "Solar North", false, ""); SolarNorth.Radius = 100000d; SolarNorth.Mass = 0; SolarNorth.TextureFileName = "C:\\Eric\\ClimateModel\\bin\\Release\\TestImage2.jpg"; AddSpaceObject(SolarNorth); /////////////////////////////////// // Set the positions of the objects from the JPL data. SetJPLTimes(); // Now that the Earth's position has been set... Vector3.Vector NorthPoleUnit = Earth.GetNorthPoleVector(); Vector3.Vector NorthPolePos = Vector3.MultiplyWithScalar(NorthPoleUnit, ModelConstants.EarthRadiusMinor + NorthPole.Radius); NorthPolePos = Vector3.Add(NorthPolePos, Earth.Position); NorthPole.Position = NorthPolePos; // Set the moon axis. Vector3.Vector MoonFirstPosition = Moon.Position; // Subtract the Earth's position so this is just in relation // to the Earth. MoonFirstPosition = Vector3.Subtract(MoonFirstPosition, Earth.Position); ECTime OneWeek = new ECTime(SunTime.GetIndex()); int SevenDays = 7 * 24 * 60; OneWeek.AddMinutes(SevenDays); JPLHorizonsData.JPLRec Rec = Moon.JPLData.GetNearestRecByDateTime(OneWeek.GetIndex()); // if( Rec.CalDate == 0 ) then it's not found. Vector3.Vector MoonSecondPosition; MoonSecondPosition.X = Rec.PositionX; MoonSecondPosition.Y = Rec.PositionY; MoonSecondPosition.Z = Rec.PositionZ; // Get the Earth's position a week from now. Rec = Earth.JPLData.GetNearestRecByDateTime(OneWeek.GetIndex()); Vector3.Vector EarthSecondPosition; EarthSecondPosition.X = Rec.PositionX; EarthSecondPosition.Y = Rec.PositionY; EarthSecondPosition.Z = Rec.PositionZ; MoonSecondPosition = Vector3.Subtract(MoonSecondPosition, EarthSecondPosition); // MoonFirstPosition = Vector3.Normalize( MoonFirstPosition ); // MoonSecondPosition = Vector3.Normalize( MoonSecondPosition ); Vector3.Vector MoonAxisPos = Vector3.CrossProduct( MoonFirstPosition, MoonSecondPosition); MoonAxisPos = Vector3.Normalize(MoonAxisPos); MoonAxisPos = Vector3.MultiplyWithScalar(MoonAxisPos, ModelConstants.EarthRadiusMinor + MoonAxis.Radius); MoonAxisPos = Vector3.Add(MoonAxisPos, Earth.Position); MoonAxis.Position = MoonAxisPos; Vector3.Vector SolarNorthPos; SolarNorthPos.X = 0; SolarNorthPos.Y = 0; SolarNorthPos.Z = 1; SolarNorthPos = Vector3.MultiplyWithScalar(SolarNorthPos, ModelConstants.EarthRadiusMinor + SolarNorth.Radius); SolarNorthPos = Vector3.Add(SolarNorthPos, Earth.Position); SolarNorth.Position = SolarNorthPos; } catch (Exception Except) { MForm.ShowStatus("Exception in SolarSystem.AddMercury(): " + Except.Message); } }