title: C# Point in polygon
body: <p>I'm trying to determine if a point is inside a polygon. the Polygon is defined by an array of Point objects. I can easily figure out if the point is inside the bounded box of the polygon, but I'm not sure how to tell if it's inside the actual polygon or not. If possible, I'd like to only use C# and WinForms. I'd rather not call on OpenGL or something to do this simple task.</p>
  
  <p>Here's the code I have so far:</p>
  
  <pre><code>private void CalculateOuterBounds()
  {
      //m_aptVertices is a Point[] which holds the vertices of the polygon.
      // and X/Y min/max are just ints
      Xmin = Xmax = m_aptVertices[0].X;
      Ymin = Ymax = m_aptVertices[0].Y;
  
      foreach(Point pt in m_aptVertices)
      {
          if(Xmin &gt; pt.X)
              Xmin = pt.X;
  
          if(Xmax &lt; pt.X)
              Xmax = pt.X;
  
          if(Ymin &gt; pt.Y)
              Ymin = pt.Y;
  
          if(Ymax &lt; pt.Y)
              Ymax = pt.Y;
      }
  }
  
  public bool Contains(Point pt)
  {
      bool bContains = true; //obviously wrong at the moment :)
  
      if(pt.X &lt; Xmin || pt.X &gt; Xmax || pt.Y &lt; Ymin || pt.Y &gt; Ymax)
          bContains = false;
      else
      {
          //figure out if the point is in the polygon
      }
  
      return bContains;
  }
  </code></pre>