Looking for a simple formula to check if a coordinate lies within an annulus sector

230 Views Asked by At

I'm building an app which has multiple sections and user needs to click inside the section to choose a "band". It looks like this: Bands

I have the co-ordinates of the points: A-J that are marked. I want an equation by which I can determine if a given co-ordinate is inside the given band. Since this image is a hand drawing, it's bad but in the app they are clean annulus sectors placed exactly as shown in this image.

1

There are 1 best solutions below

0
On

It is not easy to provide a single simple formula, also because you do not show the coordinates of the given points, so I can try to explain a possible procedure to follow.

Supposing you have Cartesian coordinates of your points, write the equation of the straight line through $ADEHJ$ (you only need two points for this), and write the equation of the line through $BCFGI$. The intersection of these lines gives you the center of the annuli, call it $\Omega$, while their slopes can be calculated form the angular coefficients of the lines (remember that $\theta=\arctan(m)$).

Next, calculate the radii of your circular arcs: the bigger radius is $r_1=\overline{A\Omega}=\overline{B\Omega}$, the second bigger is $r_2=\overline{C\Omega}=\overline{D\Omega}$, and so on.

Given the coordinates of a point $P=(x,y)$, to determine where it lays, find its distance from $\Omega$, and compare this with the radii, to see in which annulus it is. Also, the slope of the line through $P$ and $\Omega$ can tell if the point $P$ is between the two sides or if it is too much on the right or on the left.