Example 2: Moon's orbit around the earth This example can be seen as a test of the implementation: given the right initial conditions, the moon should orbit around the earth as it actually does. (mass, velocity and distance taken from https://en.wikipedia.org/wiki/Earth and
()
| 275 | |
| 276 | |
| 277 | def example_2() -> BodySystem: |
| 278 | """ |
| 279 | Example 2: Moon's orbit around the earth |
| 280 | This example can be seen as a test of the implementation: given the right |
| 281 | initial conditions, the moon should orbit around the earth as it actually does. |
| 282 | (mass, velocity and distance taken from https://en.wikipedia.org/wiki/Earth |
| 283 | and https://en.wikipedia.org/wiki/Moon) |
| 284 | No doctest provided since this function does not have a return value. |
| 285 | """ |
| 286 | |
| 287 | moon_mass = 7.3476e22 |
| 288 | earth_mass = 5.972e24 |
| 289 | velocity_dif = 1022 |
| 290 | earth_moon_distance = 384399000 |
| 291 | gravitation_constant = 6.674e-11 |
| 292 | |
| 293 | # Calculation of the respective velocities so that total impulse is zero, |
| 294 | # i.e. the two bodies together don't move |
| 295 | moon_velocity = earth_mass * velocity_dif / (earth_mass + moon_mass) |
| 296 | earth_velocity = moon_velocity - velocity_dif |
| 297 | |
| 298 | moon = Body(-earth_moon_distance, 0, 0, moon_velocity, moon_mass, 10000000, "grey") |
| 299 | earth = Body(0, 0, 0, earth_velocity, earth_mass, 50000000, "blue") |
| 300 | return BodySystem([earth, moon], gravitation_constant, time_factor=1000000) |
| 301 | |
| 302 | |
| 303 | def example_3() -> BodySystem: |
no test coverage detected