示例#1
0
        public static OrbitingBodyMathematics generate_earth()
        {
            // from http://aa.usno.navy.mil/data/docs/EarthSeasons.php
            var last_earth_perihelion = new DateTime(2016, 1, 2, 22, 49, 0);

            // from http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
            OrbitingBodyMathematics return_maths = new OrbitingBodyMathematics(
                149.60, 0.01671022, last_earth_perihelion,
                0.00005, -11.26064, 102.94719, 5.9726
                );

            // relative to the stars NOT to the sun
            // from https://en.wikipedia.org/wiki/Earth%27s_rotation#Stellar_and_sidereal_day
            double earth_rotation_period = 86164.098;
            // Assumed/approximated
            var last_earth_facing_the_sun
                = new DateTime(2016, 11, 2, 12, 00, 00);
            //Debug.Log("Last time facing the sun: " + last_earth_facing_the_sun);
            Vector3 earth_position_when_facing_the_sun
                = return_maths.current_location(last_earth_facing_the_sun);
            DateTime last_time_facing_stellar_north
                = CaclulateLastTimeFacingStellarNorth(
                      earth_rotation_period,
                      last_earth_facing_the_sun,
                      earth_position_when_facing_the_sun
                      );

            return_maths.time_last_at_original_rotation = last_time_facing_stellar_north;
            return_maths.rotation_period = earth_rotation_period;
            return_maths.default_rotation_tilt_euler_angle
                = new Vector3(-23.4f, 180.0f, 0);
            return_maths.rotation_elements_set = true;

            return(return_maths);
        }
示例#2
0
        PositionTest(OrbitingBodyMathematics planet,
                     DateTime test_time,
                     double expected_longitude,
                     double expected_latitude,
                     double expected_distance)
        {
            string expected_string
                = "\nExpected: longitude " + expected_longitude.ToString("F5")
                  + " degrees, latitude " + expected_latitude.ToString("F5")
                  + " degrees, distance " + expected_distance.ToString("F5")
                  + " AU";
            Vector3 coordinates = planet.current_location(test_time);
            Vector3 longlatdist = planet.current_longlatdist(test_time);

            Console.Write(coordinates.ToString("E"));
            Console.Write(longlatdist.ToString("F5"));

            double longitude_error            = Math.Abs(longlatdist.x - expected_longitude);
            double acceptable_longitude_error = 0.05;
            string longitude_error_message    = differing_results_error_message(
                Convert.ToString(longlatdist.x),
                Convert.ToString(expected_longitude),
                "degrees"
                );


            double latitude_error            = Math.Abs(longlatdist.y - expected_latitude);
            double acceptable_latitude_error = 0.01;
            string latitude_error_message    = differing_results_error_message(
                Convert.ToString(longlatdist.y),
                Convert.ToString(expected_latitude),
                "degrees"
                );


            double distance_error            = Math.Abs(longlatdist.z - expected_distance);
            double acceptable_distance_error = 0.00001;
            string distance_error_message    = differing_results_error_message(
                Convert.ToString(longlatdist.z),
                Convert.ToString(expected_distance),
                "AU"
                );

            Debug.Log(
                "Longitude Error: " + longitude_error + " degrees, "
                + "Latitude Error: " + latitude_error + " degrees, "
                + "Distance Error: " + distance_error + " AU"
                );

            Assert.LessOrEqual(longitude_error, acceptable_longitude_error,
                               "Longitude Error: " + longitude_error_message + expected_string);
            Assert.LessOrEqual(latitude_error, acceptable_latitude_error,
                               "Latitude Error: " + latitude_error_message + expected_string);
            Assert.LessOrEqual(distance_error, acceptable_distance_error,
                               "Distance Error: " + distance_error_message + expected_string);
        }
示例#3
0
        RotationRelativeToSunTest(double expected_angle,
                                  DateTime test_time,
                                  OrbitingBodyMathematics planet)
        {
            Vector3 planet_position
                = planet.current_location(test_time);

            Debug.Log("Planet position 3D: " + planet_position.ToString());
            Vector2 planet_position_2d
                = new Vector2(planet_position.x, planet_position.y);

            double rotation_progress
                = planet.current_stellar_day_rotation_progress(test_time);

            Debug.Log("Rotation progress: " + rotation_progress);
            Debug.Log("Anti-clockwise angle = " + (rotation_progress * 360.0));
            float angle_from_up = (float)rotation_progress * 2 * Mathf.PI;
            // angle is anti-clockwise due to earth's/solar system's rotation
            Vector2 rotation
                = new Vector2(Mathf.Sin(angle_from_up), Mathf.Cos(angle_from_up));

            Vector2 planet_normalised   = planet_position_2d / planet_position_2d.magnitude;
            Vector2 rotation_normalised = rotation / rotation.magnitude;

            Debug.Log("Planet vector: " + planet_normalised.ToString());
            Debug.Log("Rotation vector: " + rotation_normalised.ToString());

            double actual_angle
                = Vector2.Angle(planet_normalised, rotation_normalised);

            double acceptable_error = 0.1;
            double actual_error
                = Math.Abs(actual_angle
                           - expected_angle);

            string error_message = differing_results_error_message(
                Convert.ToString(actual_angle),
                Convert.ToString(expected_angle),
                "degrees"
                );

            Assert.LessOrEqual(actual_error, acceptable_error, error_message);
        }