예제 #1
0
파일: nbody.php 프로젝트: michaelprem/phc
    {
        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));
예제 #2
0
파일: nbody.php 프로젝트: n3b/hiphop-php
function n_body($n)
{
    $bodies = array(Sun(), Jupiter(), Saturn(), Uranus(), Neptune());
    OffsetMomentum($bodies);
    printf("%0.9f\n", Energy($bodies));
    for ($i = 0; $i < $n; $i++) {
        Advance($bodies, 0.01);
    }
    printf("%0.9f\n", Energy($bodies));
}