title: Given two points calculate third point at a given angle?
body: <p>I have the <strong>last two CGPoints</strong> from a <strong>Array</strong> which contains points of <strong>line drawn</strong> by the user . i need to <strong>extend the line</strong> upto a fixed distance at the same angle. so i first calculate the angle between the last two points with the help of following code</p>
  
  <pre><code>-(CGFloat)angleBetweenFirstPoint:(CGPoint)firstPoint ToSecondPoint:(CGPoint)secondPoint
  {
  
  CGPoint diff = ccpSub(secondPoint, firstPoint);
  
  NSLog(@"difference point %f , %f",diff.x,diff.y);
  
  CGFloat res = atan2(diff.y, diff.x);
  
  /*if ( res &lt; 0 ) 
  {
      res = (0.5 * M_PI) + res;
  }
  
  if ( dx&lt;0  &amp;&amp; dy&gt;0 ) {      // 2nd quadrant
      res += 0.5 * M_PI;
  } else if ( dx&lt;0 &amp;&amp; dy&lt;0 ) {        // 3rd quadrant
      res += M_PI;
  } else if ( dx&gt;0 &amp;&amp; dy&lt;0 ) {        // 4th quadrant
      res += M_PI + (0.5 * M_PI);
  }*/
  
  //res=res*180/M_PI;
  
  res = CC_RADIANS_TO_DEGREES(res);
  
  return res;
  }
  </code></pre>
  
  <p>After calculating the angle i find the extend point  with the help of following maths</p>
  
  <pre><code>-(void)extendLine
  {
  lineAngle = [self angleBetweenFirstPoint:pointD ToSecondPoint:endPt];
  
  extendEndPt.x = endPt.x - cos(lineAngle) * 200;
          extendEndPt.y = endPt.y - sin(lineAngle) * 200;
  
  // draw line unto extended point
  }
  </code></pre>
  
  <p>But the point i am getting is not right to draw the extended line at the same angle as the original line.
  I think it is because i am not getting the right angle between those last points.. what am i possibly doing wrong?? Do i need to consider the whole quadrant system while considering the angle and how? and m working in landscape mode. does that make any difference??</p>