title: Point in Polygon Algorithm
body: <p>I saw the below algorithm works to check if a point is in a given polygon from this <a href="https://stackoverflow.com/a/2922778/872344">link</a>:</p>
  
  <pre class="lang-c prettyprint-override"><code>int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
  {
    int i, j, c = 0;
    for (i = 0, j = nvert-1; i &lt; nvert; j = i++) {
      if ( ((verty[i]&gt;testy) != (verty[j]&gt;testy)) &amp;&amp;
       (testx &lt; (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
         c = !c;
    }
    return c;
  }
  </code></pre>
  
  <p>I tried this algorithm and it actually works just perfect. But sadly I cannot understand it well after spending some time trying to get the idea of it. </p>
  
  <p>So if someone is able to understand this algorithm, please explain it to me a little. </p>
  
  <p>Thank you.</p>