title: Check whether a point exists in circle sector or not with Python
body: <p>I am aware that on the net and also here the question has already been asked, but unfortunately not in the Python environment. Looking on the net, I found this (<a href="https://www.geeksforgeeks.org/check-whether-point-exists-circle-sector-not/" rel="nofollow noreferrer">Link</a>) and from there I started working on it. Since I'm using Pyglet, I wrote the function as a thread. But first, I show you what I thought and wanted to accomplish:</p>
  
  <p><a href="https://i.stack.imgur.com/l2iz8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l2iz8.png" alt="enter image description here"></a></p>
  
  <p>P = Sprite Player Position</p>
  
  <p>M = Mouse Position</p>
  
  <p>C = An imaginary circle, having as its radius the distance between P and M.</p>
  
  <p>0, 1, 2, 3, 4, 5, 6, 7 = Directions that the sprite can have</p>
  
  <p>a = Angle between one direction and another = 45°</p>
  
  <p>S = Section of the circle corresponding to the sprite direction. In simple words, if M is present in S, the direction is equal to 1</p>
  
  <p>start, end = Start Angle and End Angle</p>
  
  <p>So, in the function, I inserted a while loop. Later, I had to calculate when the radius was:</p>
  
  <pre><code>while mpc_thread:
      radius = math.hypot(mpx - cpx, mpy - cpy) + 20
  </code></pre>
  
  <p>mpx, mpy = Mouse position (X, Y)</p>
  
  <p>cpx, cpy = Sprite Player Position (X, Y)</p>
  
  <p>I used <code>math.hypot</code> thanks to this (<a href="https://stackoverflow.com/questions/5228383/how-do-i-find-the-distance-between-two-points">Link</a>). I added 20, so that the radius slightly exceeded the position of the mouse.</p>
  
  <p>Then I added a for loop to check the circle section for each direction:</p>
  
  <pre><code>while mpc_thread:
      radius = math.hypot(mpx - cpx, mpy - cpy) + 20
      for ang_obj in range(0, fchar):
          reference_angle = 360 // fchar * ang_obj
          s_angle = reference_angle - (360 / (fchar / 2))
          e_angle = reference_angle + (360 / (fchar / 2))
  </code></pre>
  
  <p>fchar = Amount of Sprite directions, in this case 8</p>
  
  <p>To find out the starting and ending angle for each direction, I divided the lap angle by twice the number of directions. Then I subtracted / added the result to the reference angle.</p>
  
  <p>From here on the problems started. Writing in the way I posted the first link, the if function didn't detect anything and if I went in negative (, I got an error. I then searched for a solution and found this (<a href="https://stackoverflow.com/questions/6270785/how-to-determine-whether-a-point-x-y-is-contained-within-an-arc-section-of-a-c">Link</a>) from the answer of user7048690. Modified the function, I got a new problem (math domain error). So I changed <code>math.sqrt</code> with <code>cmath.sqrt</code>, and it worked. But a new problem had arisen. That is, always following that answer, the if function drastically reduced FPS to 0/1. Now I don't know where to head. Can you help me with this problem? How should I build the function correctly and work properly? I hope I understood what I meant by my question.</p>