title: Trigonometry algorithm to detect the hour position on an analog clock
body: <p>I have a view in my app in the size of 312x312 that contains an analog clock like this:</p>
  <p><a href="https://i.stack.imgur.com/jbAFe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jbAFe.png" alt="Clock" /></a></p>
  <p>I have a method that gets called every time the user taps on the clock.</p>
  <p>I'm trying to use trigonometry to determinate in what hour (clock section) the user tapped, like this:</p>
  <pre><code>let touchPoint = tapGestureRecognizer.locationInView(self)
  
  let delta = CGPoint(x: center.x - touchPoint.x, y: center.y - touchPoint.y)
  let distance = hypotf(Float(delta.x), Float(delta.y))
  //Ignore points outside circle
  guard distance &lt; Float(min (frame.width / 2, frame.height / 2)) else {
      return
  }
  let angle = atan2f(Float(delta.y), Float(delta.x))
  let proportion = angle / (Float(M_PI) * 2) + 0.5
  let hour = (Int(proportion * 12) + 3) % 12 + 1
  print (hour)
  </code></pre>
  <p>but it gives me the wrong results:</p>
  <p>In format of <code>hourTapped: hourPrinted</code>:</p>
  <ul>
  <li>12:12</li>
  <li>1:1</li>
  <li>2:1</li>
  <li>3:1</li>
  <li>4:2</li>
  <li>5:1</li>
  <li>6:11</li>
  <li>7:11</li>
  <li>8:11</li>
  <li>9:11</li>
  <li>10:12</li>
  <li>11:12</li>
  </ul>
  <p>and sometimes i's even ignores taps that are inside the circle.</p>
  <p>What's wrong with this method?</p>
  <p>Thank you!</p>