title: Get angle and quadrant from three points
body: <p>Given: </p>
  
  <ul>
  <li>point clickWheelCenter</li>
  <li>point startPoint (first touch)</li>
  <li>point point (actual touch)</li>
  </ul>
  
  <p>I want to determine the angle between these three point, and I want to know, in which quadrant the last touch was found.<br>
  The calculation of the angle is working well, while the quadrant is always 1 or 2, never 3 or 4.</p>
  
  <p>Where am I wrong?</p>
  
  <pre><code>CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
  {
      CGFloat dx = point2.x - point1.x;
      CGFloat dy = point2.y - point1.y;
      return sqrt(dx*dx + dy*dy );
  };
  
  NSInteger GetQuadrant(double angle)
  {
      double sinAngle = sin(angle);
      double cosAngle = cos(angle);
      double tanAngle = tan(angle);
      double cotAngle = 1.0/tanAngle;
  
      NSLog(@"%f %f %f %f", sinAngle, cosAngle, tanAngle, cosAngle);
  
      if(sinAngle &gt; 0 &amp;&amp; cosAngle &gt; 0 &amp;&amp; tanAngle &gt; 0 &amp;&amp; cotAngle &gt; 0) return 1;
      if(sinAngle &gt; 0 &amp;&amp; cosAngle &lt; 0 &amp;&amp; tanAngle &lt; 0 &amp;&amp; cotAngle &lt; 0) return 2;
      if(sinAngle &lt; 0 &amp;&amp; cosAngle &lt; 0 &amp;&amp; tanAngle &gt; 0 &amp;&amp; cotAngle &gt; 0) return 3;
      if(sinAngle &lt; 0 &amp;&amp; cosAngle &gt; 0 &amp;&amp; tanAngle &lt; 0 &amp;&amp; cotAngle &lt; 0) return 4;
      return 0;
  }
  
  double AngleBetweenThreePoints(CGPoint point1,CGPoint point2, CGPoint point3)
  {
      CGPoint point_a = point1;
      CGPoint point_b = point2;
      CGPoint point_c = point3;
      CGFloat a, b, c;
  
      a = DistanceBetweenTwoPoints(point_b, point_c);
      b = DistanceBetweenTwoPoints(point_a, point_c);
      c = DistanceBetweenTwoPoints(point_a, point_b);
      double result = acos((b*b+c*c-a*a)/(2*b*c));
  
      NSLog(@"%d", GetQuadrant(result));
  
      return result/M_PI * 180.0;
  }
  
  
  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  {
      startPoint = [[touches anyObject] locationInView:self];
  }
  
  -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  {
      CGPoint point = [[touches anyObject] locationInView:self];
      double angle = AngleBetweenThreePoints(self.clickWheelCenter, startPoint, point);
      NSLog(@"%f", angle);    
  }
  </code></pre>