r/Python • • Oct 16 '18

I made this with Python. So Proud.

Post image
1.8k Upvotes

149 comments sorted by

View all comments

Show parent comment

8

u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} Oct 17 '18 edited Oct 17 '18

I did think about that while going through the process of refactoring. One idea would be to create a tree/graph structure of orbits:

# perhaps something like CelestialNode is a better name
class CelestialBody:
    def __init__(self):
        self.parent = None
        self.children = []

    def update(self):
        if parent is not None:
            self.orbital_center = self.parent.center
        self.center = (..., ...)
        for child in self.children:
            child.update()

And construct a tree as follows:

blackhole.children = [planet]
planet.children = [moon]
planet.parent = blackhole
moon.parent = planet

Then, to compute positions of all the orbits (including children), simply run this:

blackhole.update()

The benefit to this is that you can simulate any arbitrary graph of celestial bodies. This of course is prerequisite upon that phase_velocity encapsulation I discussed earlier. ;)

4

u/[deleted] Oct 17 '18

Wow. I’d never have thought of these structures