Exemple #1
0
    function Neptune()
    {
        return Body::NewBody(15.379697114850917, -25.919314609987964, 0.17925877295037118, 0.0026806777249038932 * DAYS_PER_YEAR, 0.001628241700382423 * DAYS_PER_YEAR, -9.515922545197159E-5 * DAYS_PER_YEAR, 5.1513890204661145E-5 * SOLAR_MASS);
    }
    function Sun()
    {
        return Body::NewBody(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS);
    }
    function OffsetMomentum(&$bodies)
    {
        $px = 0.0;
        $py = 0.0;
        $pz = 0.0;
        foreach ($bodies as $each) {
            $px += $each->vx * $each->mass;
            $py += $each->vy * $each->mass;
            $pz += $each->vz * $each->mass;
        }
        $bodies[0]->vx = -$px / SOLAR_MASS;
        $bodies[0]->vy = -$py / SOLAR_MASS;
        $bodies[0]->vz = -$pz / SOLAR_MASS;
    }
}
$bodies = array(Body::Sun(), Body::Jupiter(), Body::Saturn(), Body::Uranus(), Body::Neptune());
Body::OffsetMomentum($bodies);
$n = $argc == 2 ? $argv[1] : 1;
printf("%0.9f\n", Energy($bodies));
for ($i = 0; $i < $n; $i++) {
    Advance($bodies, 0.01);
}
printf("%0.9f\n", Energy($bodies));