Skip to content

Instantly share code, notes, and snippets.

@rileypeterson
Last active May 10, 2019 22:04
Show Gist options
  • Save rileypeterson/6afe504250684c5ddf7aec26ddb89378 to your computer and use it in GitHub Desktop.
Save rileypeterson/6afe504250684c5ddf7aec26ddb89378 to your computer and use it in GitHub Desktop.
Plot rotated ellipse
""" From: https://math.stackexchange.com/a/2647450/635480 """
import numpy as np
import matplotlib.pyplot as plt
def plot_rotated_ellipse(cx=1, cy=2, rx=3, ry=0.5, theta=np.pi/4):
alpha = np.linspace(0, 2*np.pi, 100)
x = rx*np.cos(alpha)*np.cos(theta) - ry*np.sin(alpha)*np.sin(theta) + cx
y = rx*np.cos(alpha)*np.sin(theta) + ry*np.sin(alpha)*np.cos(theta) + cy
plt.plot(x, y)
plot_rotated_ellipse()
@rileypeterson
Copy link
Author

image

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