Skip to content

Instantly share code, notes, and snippets.

@robintw
Created November 22, 2015 20:05
Show Gist options
  • Save robintw/0abb2426b0886c303078 to your computer and use it in GitHub Desktop.
Save robintw/0abb2426b0886c303078 to your computer and use it in GitHub Desktop.
def make_ellipse(x, x0, y, y0, theta, a, b):
"""Creates an ellipse in an array.
Parameters:
x: Array resulting from meshgrid function
x0: Unused
y: Array resulting from meshgrid function
y0: Unused
theta: Angle of rotation of the ellipse, in radians
a: Length of major axis
b: Length of the minor axis
Returns:
Array with the ellipse in it.
"""
c = np.cos(theta)
s = np.sin(theta)
a2 = a**2
b2 = b**2
#xnew = x - x0
#ynew = y - y0
xnew = x
ynew = y
ellipse = (xnew * c + ynew * s)**2 / a2 + (xnew * s - ynew * c)**2 / b2
return ellipse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment