title: a javascript function for 2d collision detection with rotated rectangles?
body: <p>I'm making a game in javascript and I cant find anything like a function that will take 2 bounding box objects and return true if they intersect. all the examples I've found seem far too complex for my little game and most are language specific :/</p>
  
  <pre><code>//my box object
  function bounding_box (x, y, width, height, rotation) {
    var box = {};
    box.x = x;
    box.y = y;
    box.w = width
    box.h = height;
    box.r = rotation; //degrees from origin - all objects in the game have the same rotation origin
    return box;
  }
  
  function boxes_collide (a, b) {
    //if collision return true
    //else return false
  
    //my box collision function at the moment
    //doesn't work with rotation
    return !(
        ((a.y + a.h) &lt; (b.y)) ||
        (a.y &gt; (b.z + b.h)) ||
        ((a.x + a.w) &lt; b.x) ||
        (a.x &gt; (b.x + b.h))
    );
  }
  
  //create boxes
  var boxa = bounding_box(0, 0, 5, 3, 45);
  var boxb = bounding_box(1, 3, 4, 2, 90);
  
  //test for collision
  if (boxes_collide (boxa, boxb)) {
    alert('collision');
  }
  </code></pre>
  
  <p>I've been stuck for hours on this little problem, any help would be appreciated! :)</p>