/** * Calculates the nutations in longitude (Δψ) and latitude (Δε) for a date * * @param AstroDate $date * @return static * * @see Meeus, Jean. Astronomical Algorithms. Richmond, Virg.: Willmann-Bell, * 2009. 143-147. Print. */ public static function find(AstroDate $date) { // Time factor $t = ($date->copy()->toUTC()->jd - 2451545.0) / 36525; /* * Required terms * ---------------- * D = mean elongation of the Moon from the Sun * M = mean anomaly of the Earth * M´ = mean anomaly of the Moon * F = argument of latitude for Moon * Ω = long. of asc. node for Moon's mean ecl. orbit (mean equi. of date) */ $coeffD = [297.85036, 445267.1148, -0.0019142, 1 / 189474]; $coeffM = [357.52772, 35999.05034, -0.0001603, -1 / 300000]; $coeffM´ = [134.96298, 477198.867398, 0.0086972, 1 / 5620]; $coeffF = [93.27191000000001, 483202.017538, -0.0036825, 1 / 327270]; $coeffΩ = [125.04452, -1934.136261, 0.0020708, 1.0 / 450000]; // Calculate the terms $D = Angle::deg(static::Horner($t, $coeffD))->norm(); $M = Angle::deg(static::Horner($t, $coeffM))->norm(); $M´ = Angle::deg(static::Horner($t, $coeffM´))->norm(); $F = Angle::deg(static::Horner($t, $coeffF))->norm(); $Ω = Angle::deg(static::Horner($t, $coeffΩ))->norm(); // Nutation coefficient terms $nutationTerms = static::NutationTerms(); // Evaluate the nutation terms $Δψ = 0; $Δε = 0; for ($i = 0; $i < count($nutationTerms); $i++) { $row = $nutationTerms[$i]; $arg = 0 + $row[0] * $D->rad + $row[1] * $M->rad + $row[2] * $M´->rad + $row[3] * $F->rad + $row[4] * $Ω->rad; $Δψ += ($row[5] + $row[6] * $t) * sin($arg) / 10000.0 / Time::SEC_IN_HOUR; $Δε += ($row[7] + $row[8] * $t) * cos($arg) / 10000.0 / Time::SEC_IN_HOUR; } // Store as angles $Δψ = Angle::deg($Δψ); $Δε = Angle::deg($Δε); // Return the nutation return new Nutation($Δψ, $Δε); }
/** * @covers Marando\AstroDate\AstroDate::sub */ public function testSub() { $tests = [[Time::min(10), 2015, 11, 1, 12, 40, 10], [Time::sec(33), 2015, 11, 1, 12, 49, 37], [Time::days(3), 2015, 10, 29, 12, 50, 10], [Time::days(15), 2015, 10, 17, 12, 50, 10], [Time::days(365), 2014, 11, 1, 12, 50, 10], [Time::hours(13), 2015, 10, 31, 23, 50, 10]]; foreach ($tests as $t) { $time = $t[0]; $y = $t[1]; $m = $t[2]; $d = $t[3]; $h = $t[4]; $i = $t[5]; $s = $t[6]; $dt0 = new AstroDate(2015, 11, 1, 12, 50, 10); $dt = $dt0->copy()->sub($time); $this->assertEquals($y, $dt->year, $t[0] . ' y'); $this->assertEquals($m, $dt->month, $t[0] . ' m'); $this->assertEquals($d, $dt->day, $t[0] . ' d'); $this->assertEquals($h, $dt->hour, $t[0] . ' h'); $this->assertEquals($i, $dt->min, $t[0] . ' i'); $this->assertEquals($s, $dt->sec, $t[0] . ' s'); } }