[Python] Why does manim create a circle for a set of points that form an ellipse?

Discussão em 'Python' iniciado por Stack, Setembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    trying to animate the orbit of a planet in manim . If I plot the data returned from the compute_orbit() function in matplotlib for say , I get an ellipse , but the same set of points create a circle in manim. I'm not sure why manim behaves this way !

    Code Snippet


    from manim import *
    from astroquery.jplhorizons import Horizons
    import numpy as np
    import scipy.integrate
    def get_initial_conditions(planet_id):
    obj = Horizons(id=planet_id, location='@sun', epochs=2000.0)
    eph = obj.vectors()
    position = np.array([eph['x'][0], eph['y'][0], eph['z'][0]]) * 1.496e11
    velocity = np.array([eph['vx'][0], eph['vy'][0], eph['vz'][0]]) * (1.496e11/86400)
    scale_factor_position = 1
    scale_factor_velocity = 1
    return {
    "position": np.array(position) / scale_factor_position,
    "velocity": np.array(velocity) / scale_factor_velocity
    }

    def compute_orbit(central_mass=1.989e30,rotating_mass=5.972e24, dt=10000, total_time=31536000):
    initial_conditions_data = get_initial_conditions(399)
    initial_conditions = [
    initial_conditions_data['position'][0], initial_conditions_data['velocity'][0],
    initial_conditions_data['position'][1], initial_conditions_data['velocity'][1],
    initial_conditions_data['position'][2], initial_conditions_data['velocity'][2]
    ]

    def f(t, state):
    x, vx, y, vy, z, vz = state
    r = np.sqrt(x**2 + y**2 + z**2) + 1e-5
    G = 6.67430e-11
    Fx = -G * central_mass * rotating_mass * x / r**3
    Fy = -G * central_mass * rotating_mass * y / r**3
    Fz = -G * central_mass * rotating_mass * z / r**3
    return [vx, Fx / rotating_mass, vy, Fy / rotating_mass, vz, Fz / rotating_mass]


    t_span = (0, total_time)
    t_eval = np.arange(0, total_time, dt)
    sol = scipy.integrate.solve_ivp(
    f,
    t_span,
    initial_conditions,
    t_eval=t_eval,
    rtol=1e-3,
    atol=1e-6)
    x = sol.y[0] / 1e11
    y = sol.y[2] / 1e11
    z = sol.y[4] / 1e11
    positions = np.column_stack((x, y, z))
    return positions


    class Space(ThreeDScene):
    def construct(self):
    orbit = ThreeDVMobject()
    data = compute_orbit()
    orbit.set_points_as_corners(data)
    self.add(orbit)
    self.wait(3)

    Continue reading...

Compartilhe esta Página