Skip to content

Instantly share code, notes, and snippets.

@RichardEllicott
Created December 10, 2023 15:08
Show Gist options
  • Save RichardEllicott/9db7aecc1f1c7ee07323d5cebf2879a3 to your computer and use it in GitHub Desktop.
Save RichardEllicott/9db7aecc1f1c7ee07323d5cebf2879a3 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
def plot_kepler_orbit(semi_major_axis, eccentricity, num_points=1000):
# Calculate the semi-minor axis
semi_minor_axis = semi_major_axis * np.sqrt(1 - eccentricity**2)
# Generate theta values (angle from the positive x-axis)
theta = np.linspace(0, 2*np.pi, num_points)
# Parametric equations for the ellipse
x = semi_major_axis * np.cos(theta)
y = semi_minor_axis * np.sin(theta)
# Rotate the ellipse to align with the orbit
rotation_angle = np.arctan2(y, x)
x_rotated = x * np.cos(rotation_angle) - y * np.sin(rotation_angle)
y_rotated = x * np.sin(rotation_angle) + y * np.cos(rotation_angle)
# Plot the Kepler orbit
plt.plot(x_rotated, y_rotated, label='Kepler Orbit')
plt.scatter([0], [0], color='red', label='Central Mass (e.g., Sun)')
plt.title('Kepler Orbit')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
# Example usage
semi_major_axis = 2.0 # Adjust the semi-major axis as needed
eccentricity = 0.5 # Adjust the eccentricity as needed
plot_kepler_orbit(semi_major_axis, eccentricity)
@RichardEllicott
Copy link
Author

generated by chat GP, probabally wrong makes an egg shape

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment