Created
December 10, 2023 15:08
-
-
Save RichardEllicott/9db7aecc1f1c7ee07323d5cebf2879a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
generated by chat GP, probabally wrong makes an egg shape