0
$\begingroup$

I am given the center of circle $C_x$,$C_y$ , radius $R$ and the angle of the sector $\theta$. We go clockwise.

For eg- If Center is $(0,0)$ and $R= 10$ then circle is started from line segment formed by line segment $(0,0),(0,10)$ and the $\theta$ is given in reference to it.

I am given a point $X$, $Y$ and I have to find the position of point (inside the sector or not).

So I calculated the $r$ distance from $C_x,C_y$ to point $X,Y$. I know the first condition should be that $r \le R$.

How do I check for the angle ??

1 Answers 1

1

Let $\hat{\alpha} = \operatorname{atan2}(Y-C_y,X-C_x)$ and define $$ \alpha = \left\{ \begin{array}{rr} \pi/2 - \hat{\alpha}, & -\pi < \hat{\alpha} \leq \pi/2\\ 5\pi/2 - \hat{\alpha}, & \pi/2 < \hat{\alpha} \leq \pi \end{array} \right. $$ If $\alpha \leq \theta$ and $(Y-C_y)^2 + (X - C_x)^2 \leq R^2$, then the point $(X,Y)$ belongs to the sector.

  • 0
    How did you get the conditions for $\alpha$ ? I can't seem to grasp it.2017-01-07
  • 0
    The function $\operatorname{atan2}(Y,X)$ gives you the angle measured from the positive $x$-axis in the counter-clockwise direction to points in positive half-plane $(y \geq 0 \iff 0 \leq \hat{\alpha} \leq \pi)$ and in the clockwise direction to points in the negative half-plane $(y < 0 \iff -\pi < \hat{\alpha} < 0)$. Since you measure $\theta$ from the positive $y$-axis with the clockwise direction as being positive, I have adjusted the angle returned from $\operatorname{atan2}$ to agree with that. It may help to understand my answer if you draw yourself a picture for the various cases.2017-01-07
  • 0
    Thanks, I got it. But there is one case in which this failed when it was very close : when $(Y-C_y)=5$ , $(X-C_x)=5$ , $\theta= 0.24* \pi$ and it is supposed to be out but it's coming inside.2017-01-07
  • 0
    The formula returns the value $\alpha = \pi/4 > 0.24\pi = \theta$, so the point should fall outside the sector as desired.2017-01-08
  • 0
    Thanks. It was an error due to the precision.2017-01-08