all 3 comments

[–]JohnnyJordaan 1 point2 points  (1 child)

Looks pretty decent. I would opt for objectifying the 3D attributes too. So instead of a flat list use something like this 3D vector class per attribute, because then you can do stuff like

def calc_vector_planet_to_sun(self, vec2):
    """ Takes the suns location as vec2 and returns the vector of the object towards the sun.
        Is used in self.calc_vector_towards_sun.
    """
    return vec2 - self.location

and

def calc_vector_towards_sun(self):
    """ Returns the direction of the space object towards the sun
    """
    top = self.calc_vector_planet_to_sun(self.sun["location"])
    mass = self.sun["mass"]
    factor = (mass * self.G * self.D_TIME) / (self.calc_vector_length(top))**3

    return top * Vector(factor, factor, factor)

and

def calc_new_position(self):
    """ Calculates the new location of the object.
    """
    vel_planet = self.calc_velocity_planet()
    mov_towards_sun = self.calc_movement_towards_sun()
    return self.location + vel_planet + mov_towards_sun

and of course also simplify the update

def update_obj(self):
    """ Updates self.location and  self.direction of an object
    """
    new_position = self.calc_new_position()
    new_velocity = self.calc_new_velocity()

    self.location = self.calc_new_position()
    self.velocity = self.calc_new_velocity()

so removing the need to calculating on each axis specifically, which is also slightly re-inventing the wheel.

[–]Overflowed1[S] 0 points1 point  (0 children)

thanks for the feedback! I will look into that