title: Count Hexagons inside a Rectangle?
body: <p>I'm looking for an algorithm to count hexagons that fall within a rectangular area, whether cropped or not.</p>
  
  <p>I know the following:</p>
  
  <pre><code>rectWidth = 1280;
  rectHeight = 720;
  hexRadius = 50; // middle to corner
  hexHeight = hexRadius * 2;
  hexShortSpan = hexRadius * 0.5;
  hexLongSpan = cos(radians(30)) * hexRadius;
  hexWidth = hexLongSpan * 2;
  hexSide = hexRadius + hexShortSpan; // this is not a side but side + shortSpan for horizontal rows
  </code></pre>
  
  <p>Can't figure out the mod op to get the right result.</p>
  
  <pre><code>float A = rectWidth / hexWidth;
  float B = rectHeight / hexSide;
  float hexCount = A * B +????;
  // etc. etc. not sure about the rest...
  </code></pre>
  
  <p>Rob</p>
  
  <p>Here's an image…</p>
  
  <p><a href="http://moggach.com/media/img/hexGrid.jpg" rel="nofollow">http://moggach.com/media/img/hexGrid.jpg</a></p>