title: C# XNA Calculate distance between rectangles (rotation-friendly)
body: <p>Here's 2 methods available;</p>
  
  <pre><code>if(rectangle.Intersects(otherRectangle))
  {
      //collision stuff
  }
  </code></pre>
  
  <p>Catch: Only works with non-rotating rectangles.</p>
  
  <pre><code>if(Vector2.Distance(player.pos, enemy.pos) &lt; 50)
  {
      //collision stuff
  }
  </code></pre>
  
  <p>Catch: Only works with circles.</p>
  
  <p><strong>What I want is to calculate x and y in this image:</strong> <img src="https://i.imgur.com/TY192Ra.png" alt="problem"></p>
  
  <p><strong>Facts</strong></p>
  
  <p>The width and length of both rectangles is defined, along with their rotations.
  I can calculate D using the Pythagorean theorem. 
  But the TRUE distance is D - (X + Y).</p>
  
  <p><strong>General approach</strong></p>
  
  <p>Evidently x and y can be calculated using the Cosine rule. 
  But I only have the width or length and the angle between the two shapes.</p>
  
  <p><strong>Complication</strong></p>
  
  <p>Plus, this needs to work for any rotation.
  The rectangle on the left could be rotated in any direction, and x would be different depending on said rotation.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How would I calculate x and y?
  I just want an effective collision detection method more complex than bounding boxes and Pythagoras' theorem.</p>