title: How to calculate a point out of an angle and a distance?
body: <p>I searched and implemented things from this forum, it doesn't come out right.
  What I'm trying to achieve is to calculate a <code>spawnPoint</code> for player bullets relative to his <code>position</code> and <code>rotation</code>.</p>
  
  <p>The <code>spawnPoint</code> should be and his <code>X + his width</code> (the player is set to point to the right by default) and <code>y + height/2</code> (to spawn from his center on the <code>Y</code> axis).</p>
  
  <p>This is what I got from this forum:</p>
  
  <pre><code>this.bulletSpawn.x = (float)(this.position.x + this.width/2 + this.width * Math.cos(rotation));
  this.bulletSpawn.y = (float)(this.position.y + this.height/2 + this.height/2 * Math.sin(rotation));
  </code></pre>
  
  <p>The <code>rotation</code> is in Radians. The <code>this</code> is the <code>Player</code> class.</p>
  
  <p>Images showing what I expect to happen:</p>
  
  <ul>
  <li><a href="http://i.stack.imgur.com/iGpIj.jpg" rel="nofollow">Original Position</a></li>
  <li><a href="http://i.stack.imgur.com/upb00.jpg" rel="nofollow">Expected Behaviour</a></li>
  </ul>
  
  <p>The red dot is the <code>spawnPoint</code> I'm trying to calculate knowing the player <code>position</code> and <code>rotation</code>.
  The player Sprite is what rotates, and it rotates related to his center x and y, which is done with a lib, i do not have these variables. The entire arrow would be the player , the arrow direction is where the player is pointing at, and the red dot would be the bulletSpawn point (or the expected one)</p>
  
  <p>Using the code I posted, the bullets seem to be spawning from somewhere else. Even at the beggining they have an offset and when I rotate the player the <code>spawnPoint</code> seems to be relative to a different origin than what I'm expecting.</p>
  
  <p>This is the bullet position code:</p>
  
  <pre><code>position.x = holder.bulletSpawn.x - (float)(this.width/2 * holder.rotation);
  position.y = holder.bulletSpawn.y - (float)(this.height/2 * holder.rotation);
  </code></pre>
  
  <p>This is inside the <code>Bullet</code> class. The <code>position</code> variable is a <code>Vector2</code> of <code>bullet</code>, and <code>holder</code> is the player instance. This code is merely to give an offset for the bullet to spawn at the center of its own size</p>
  
  <p>I added some fixes related to the comments, but the bullets still have a tiny offset that looks wrong at certain angles.
  Basically the distance i want to get is the width of the player, and his center y which is height/2.</p>