1

I'm making a program to simulate the retrograde motion of mars visible from Earth. So it's a plan view of Earth and Mars orbiting the sun There is also a line going from Earth to Mars. However, I need it to intersect the point that is Mars and keep going until it intersects the line x = 15

another user sent me this code with

My previous code

import math
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def _update_plot(i, fig, scat, l):
    scat.set_offsets(([math.cos(math.radians(i))*5, math.sin(math.radians(i))*5], [math.cos(math.radians(i/2))*10, math.sin(math.radians(i/2))*10], [0, 0]))
        l.set_data(([math.cos(math.radians(i))*5,math.cos(math.radians(i/2))*10],[math.sin(math.radians(i))*5,math.sin(math.radians(i/2))*10]))
    return [scat,l]

fig = plt.figure()

x = [0]
y = [0]

ax = fig.add_subplot(111)
ax.set_aspect('equal')
ax.grid(True, linestyle = '-', color = '0.10')
ax.set_xlim([-11, 11])
ax.set_ylim([-11, 11])

l, = plt.plot([],[], 'r--', zorder=1)
scat = plt.scatter(x, y, c = x, zorder=2)
scat.set_alpha(0.8)

anim = animation.FuncAnimation(fig, _update_plot, fargs = (fig, scat, l),
                           frames = 720, interval = 10)

plt.show()

another users code

def _update_plot(i, fig, scat, l):
    angle = math.radians(i)
    sun_pos = np.array([0., 0.])
    earth_pos = np.array([math.cos(angle)*5, math.sin(angle)*5])
    mars_pos = np.array([math.cos(angle / 2.) * 10, math.sin(angle / 2.) * 10])

    # compute the unit vector that points from Earth to Mars
    direction = mars_pos - earth_pos
    direction /= np.sqrt(np.dot(direction, direction))

    # find out where the line would intersect the x = 15 axis
    start_from = earth_pos
    alpha = (15 - start_from[0]) / direction[0]
    # if alpha comes out to be negative we picked the "wrong" planet
    if alpha < 0:
            start_from = mars_pos
            direction = -direction
            alpha = (15 - start_from[0]) / direction[0]
    y_line = start_from[1] + alpha * direction[1]

    # draw the planets
    scat.set_offsets((earth_pos, mars_pos, sun_pos))
    # draw the line
    l.set_data(([start_from[0], 15], [start_from[1], y_line]))
    return [scat,l]

So the goal is for there to be a line going from 'Earth' (the innermost moving object) to the line x=15 as well as the other moving object in between.

I also suppose the line should only appear when the line will hit x=15 so only during the first and last quarter of the orbit period

Edgar Nash
  • 63
  • 9
  • its highly unclear what you asking do you have an image/sketch of the problem ? by plan view you mean 2D planar view (projection) like this [Calculate an intercept to an orbit for a given speed.](https://stackoverflow.com/a/51854275/2521214)? What exactly is the problem you are stuck with ? what are knowns and unknowns ... voting for close for now ... – Spektre Jan 28 '19 at 11:04
  • https://docs.google.com/drawings/d/1n9hitW1cD_xZHCnIgO4HK6owywstAS-hkM3K9HaEBUg/edit?usp=sharing – Edgar Nash Jan 28 '19 at 13:59
  • here is what someone suggested from another post I made on here but here the line starts from Earth (inner planet) to Mars but stops at Mars. I want the line to continue and instead stop at where it meets the line x = 15 – Edgar Nash Jan 28 '19 at 14:02
  • You still did not specify if its 2D (if `x = 15` is line than it is 2D I assume ecliptic plane projection) and where is your problem exactly (computing planets, endpoints, rendering, ...? ) btw. the current description is odd ... did you mean you want semi axis instead of line segment (so not stopping at line `x=15` but ending on the edge of view instead...) also `x=15` does not correspond to orbital scales so what are the units / scale ? – Spektre Jan 29 '19 at 08:50

0 Answers0