title: View frustum culling a box in Java
body: <p>Given a view frustum (defined by x,y,z camera position, rotation [0-360) and pitch [0-180), as well as a viewing angle (e.g. 45)) what is the (preferably fastest) Java code for determining if a box (defined by two opposing corner points) is partly or entirely within that frustum?</p>
  
  <p>More precisely, how can I complete the following?</p>
  
  <pre><code>static boolean isBoxInFrustum(float cx, float cy, float cz, // Vector camera,
          float rotation, float pitch, float angle, 
          float p1x, float p1y, float p1z,    // Vector point1,
          float p2x, float p2y, float p2z) {  // Vector point2
      //...
  }
  </code></pre>
  
  <p>A C++ implementation can be found at <a href="http://www.lighthouse3d.com/tutorials/view-frustum-culling/" rel="nofollow">http://www.lighthouse3d.com/tutorials/view-frustum-culling/</a></p>
  
  <p>edit: Here's the 2d version, which is only 4 lines and seems to me easy enough to understand at a glance - how can it be modified to be a 3d check?</p>
  
  <pre><code>static boolean isPointInFrustum(
          Vector cam, float rot, float pitch, float ang, Vector point) {
      Vector diff = cam.minus(point);
      float deg = Maths.arctan(diff.y, diff.x) + rot + 360;
      deg %= 360;
      return (deg &gt; 180-ang &amp;&amp; deg &lt; 180+ang);
  }
  </code></pre>