title: Swift calculating a new point x distance in y direction
body: <p>I'm doing some code in sprite kit and want to calculate a position of a sprite based on a start location and moving it In a given direction and distance. For example, assuming I'm using degrees with 0 meaning straight up, I want to move the sprite from it's current position in the 45 degree (up and right) direction 10 points.</p>
  
  <p>Trigonometry isn't my strength and I've been struggling to figure out how to apply it. Moving in the 45 degree direction seems pretty straight forwards, but I'm not sure how to calculation for directions like 110 (down and right) or 225 (down and left).</p>
  
  <p>My first attempt looks like this:</p>
  
  <pre><code>public func offset(byDistance distance:CGFloat, inDirection degrees:CGFloat) {
      let vertical = sin(degrees) * distance
      let horizontal = sqrt(pow(distance, 2.0) + pow(vertical, 2.0))
      self.position = self.position.applying(CGAffineTransform(translationX:horizontal, y:vertical))
  }
  </code></pre>
  
  <p>But I don't think it's working as the results look like this:</p>
  
  <pre><code>Direction 45, distance 88.26 -&gt; New location {75.10, 115.88}
  Direction 135, distance 88.26 -&gt; New location {7.79, 88.60}
  Direction 225, distance 88.26 -&gt; New location {-82.09, 120.53}
  Direction 315, distance 88.26 -&gt; New location {65.76, 110.06}
  </code></pre>
  
  <p>Can anyone give me some clues as to where I've gone wrong?</p>