title: Producing an array from an ellipse
body: <p>I have an equation that creates an ellipse in the general form x^2/a^2 + y^2/b^2 = 1. I wish to produce an array whereby all points inside the ellipse are set to one and all points outside are a zero. This array is then to be convolved with another.</p>
  
  <p>So far I have tried to create an empty array of the size I want the go through all x,y positions calculating x^2/a^2 + y^2/b^2 = 1. If the general form is less than one enter a one into the array, otherwise continue to the next x,y position.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    arr = numpy.array(im) 
      sh = numpy.shape(arr)
      ar = numpy.empty(sh)
  
      for x in range (sh[0]):
          xx = x*x
          for y in range (sh[1]):
              yy = y*y
              ellips = xx/(a*a)+yy/(b*b)
              if ellips &lt; 1:
                  ar[xx,yy] = '1'
              else:
                  break
  </code></pre>
  
  <p>However, this doesn't produce what I expect as my ellipse is always centered at (0,0) thus I expect the ones to be in the center of my array but they appear in the top left corner.</p>
  
  <p>Does anyone have insight as to where I have gone wrong? Or perhaps a better way to produce my array?   </p>
  
  <p>---Edit---</p>
  
  <p>Having tried EOL's answer I receive an ellipse array however it doesn't match the ellipse it should model. Here is a picture to illustrate what I mean: <a href="http://i.imgur.com/M4vh4il.jpg?1" rel="nofollow">http://i.imgur.com/M4vh4il.jpg?1</a>
  The ellipse array doesn't have the rotation of the ellipse. 
  The code to produce the ellipse and ellipse array is as follows:</p>
  
  <pre><code>    def Ellipssee(z,stigx,stigy):
          points=100 #Number of points to construct the ellipse
          x0,y0 = 0,0 #Beam is always centred
          z0 = 4 # z0 a constant of the device
          al = 2 # alpha a constant of the device
          de = sqrt((stigx**2 + stigy**2))
          ang = arctan2(stigy, stigx) # result in radians
          a = (z+de-z0)*al
          b = (z-de-z0)*al 
          cos_a,sin_a=cos(ang),sin(ang)
          the=linspace(0,2*pi,points)
          X=a*cos(the)*cos_a-sin_a*b*sin(the)+x0
          Y=a*cos(the)*sin_a+cos_a*b*sin(the)+y0
  
          img = Image.open("bug.png").convert("L") # load image for array size
          arr = np.array(img) 
          sh = np.shape(arr)
  
          nx = sh[0]   # number of pixels in x-dir
          ny = sh[1]   # number of pixels in y-dir
  
          x0 = 0;  # x center, half width                                       
          y0 = 0;  # y center, half height                                      
          x = np.linspace(-60, 60, nx)  # x values of interest
          y = np.linspace(-30, 30, ny)  # y values of interest
          ellipseArr = ((x-x0)/a)**2 + ((y[:,None]-y0)/b)**2 &lt;= 1
  </code></pre>
  
  <p>I have been calling the method with the values <code>Ellipse(1,6,8)</code>.</p>
  
  <p>Why is the rotation being lost in the array creation?</p>