5

Prologue: I have very moderate knowledge of mathematics (highschool sophomore level). Any explanation needs to be broken down to chewable bits. I'm sorry if this inconveniences you guys.

I have the following problem: How do I find out if a circle and an arc sector of another circle intersect?

enter image description here

The small circles above are examples. The ones in red are the ones that do not intersect, the ones in green are that ones that do intersect.

This is my approach, based on immediate data that I have available about the arc sector and the other circle:

let $A$ be the arc sector of a circle defined as follows:

  • $C$ $(Cx, Cy)$ is the centre of the circle.
  • $D$ is a radius of the circle, of which we know the length. ($D$ stands for direction).
  • $\alpha$ the angle of arc sector, so that $D$ bisects $\alpha$

We also know the point where $D$ intercepts the circle (not named in the drawing above)

\begin{equation} \\ \end{equation}

For the smaller circles:

let $P$ be a circle, defined as follows:

  • $c$ $(cx, cy)$ is the centre of the circle.
  • $r$ is the radius of the circle.

First, i check if $P$ is inside or intersects the circle defined by $C$ and $D$:

$$(D + r)^2 \geq (Cx - cx)^2 + (Cy - cy)^2$$ (sum of the radii squared is greater than or equal to the squared distance between $C$ and $c$)

Secondly, if the above is true, my plan is to find the angle between the radius $D$ and each of the two tangents to circle $P$ (there's a problem here, read bellow) that pass through $C$; if any of these two angles is equal to or smaller than $\frac{\alpha}{2}$, then I have an intersection.

Note: The problem with this approach is that it doesn't work in case $C$ is inside $P$ (like the small green circle that contains C in figure 1). I disregard this case, because I don't know how to deal with it. In short, I know my answer is wrong, I'm just letting you know what I have so far. Considering that the set of arguments of my function that will result in $P$ containing $C$ is almost negligible, a result where those cases are excluded is acceptable, even if not ideal.

enter image description here

I know how to find the angle between $Cc$ and the tangents:

$$\measuredangle uCc = \measuredangle vCc = \arcsin(\frac{r}{d})$$

But I think that's irrelevant.

What I need is to find the angle between each of the tangents (the black lines) and $D$, and if such angle is equal to or lesser than $\frac{\alpha}{2}$, then it's a hit, otherwise, a miss.

I think I need to find the slopes of the lines $Cu$ and $Cv$, so I can compare it to the slope of $D$ to find the angle between those lines, using the relation:

$$\tan(\theta) = \left| \frac{m_{a} - m_{b}}{1 + m_{a}m_{b}}\right|$$

For me to find the slopes of those lines, I think I need to know the points $u$ and $v$.

There's one last problem with my approach: the function $arctan$ (which I would use to find $\theta$, given $\tan(\theta)$) can give me wrong results in case one of the circles is in a position inside the opposite arc $A'$ formed by extending $D$ and the legs of the arc into diameters. I hear $arctan2$ can fix this, but I'm not sure how to use it.

If there's an easier solution than mine, it's very welcome. As I mentioned, the third point of the triangle is necessary for me to know how to solve this according to my approach so far. If there's a better and faster way, please let me know, since this problem is to be used in a computational algorithm.

  • Do the small circles have all the same radius? – N74 May 05 '17 at 20:33
  • @N74 Yes, they do. – FinnTheHuman May 05 '17 at 20:36
  • 2
    I think the best strategy is to consider the shape you have offsetting the sector by the diameter of the small circles. You have then to find if the centre of any small circle is inside that shape. The shape is a circular sector with the edges smoothed, quite easy to identify. – N74 May 05 '17 at 20:53
  • @N74 I don't understand. – FinnTheHuman May 05 '17 at 21:15
  • @N74 means what is called the dilated set of your sector. – Jean Marie May 05 '17 at 21:38
  • ... in other words, it is the convolution of your sector with a "prototype" of your disks. – Jean Marie May 05 '17 at 22:08
  • @JeanMarie If you could point out some resources so I could at least know what you're talking about, I would appreciate it very much! I'm sorry, I should have opened my question with this: I'm a highschool student who likes to write computer code. – FinnTheHuman May 05 '17 at 22:21
  • 1
    Understood. I will write tomorrow a little piece of text and/or piece of Matlab code. But now it's one o'clock in the morning Central European Time...I go to bed.... – Jean Marie May 05 '17 at 23:07
  • You are hardly the first high school student here. As long as your question is mathematical, well-explained, and shows that it is something you are trying to learn (as opposed to something you are trying to avoid learning by having us provide the answer for you), it is a good question and will be well-received. Your question easily passes all of those. – Paul Sinclair May 06 '17 at 03:31
  • In addition to throwing out any circles whose centers are $> D+r$ apart, you can automatically include any circles whose centers are less than $r$ apart. This is important, because the remainder of the convoluted boundary JeanMarie describes consists of two lines. So once you know those lines, is just a matter of testing if the remaining undecided circle centers are between them or outside. And that is just two linear equalities to test. – Paul Sinclair May 06 '17 at 03:35

1 Answers1

1

Since JeanMarie hasn't done so, let me post my explanation. In this figure is (rendered in Paint, so please excuse the crudity of the model) the dilated set JeanMarie was talking about.

dilated boundary

As you can see, it can be created by drawing the smaller circles around each of the three corners of your sector. Then the circular boundary of the sector increases in radius by $r$, until it is tangent to the two small circles. And each of the sector sides also moves out by $r$ until it also is tangent to the small circles. The remainder of the dilated set boundary is the arcs of the small circles between the points of tangency.

Any circle of radius $r$ will intersect the sector if and only if its center is in this dilated set. So how do we test if the center is in this set? With tests for each of the various segments of the boundary. To simplify matters, I am going to assume the big circle is centered at $(0,0)$, that the center of the sector is horizontal. Label the upper and lower corner points of the sector $(Da, Db)$ and $(Da, -Db)$, respectively. It follows that $a = \cos (\alpha/2)$ and $b = \sin(\alpha/2)$.

Since the sector sides pass through the origin, they will have equations $bx - ay = 0$ for the upper side and $bx + ay = 0$ for the lower side. Since $\sqrt{a^2 + b^2} = 1$, to move the line by $r$ is just a matter of changing the constant by $r$. The upper equation becomes $bx - ay = r$, while the lower equation becomes $bx + ay = -r$ (some care has to be taken with signs here). More importantly, $$bx - ay \le r$$ is satisfied by all points below the top side, while $$bx + ay \ge -r$$ is satisfied by all points above the bottom line.

So the test is this. Let $(x,y)$ be the center of the circle to be tested, and calculate $d2 = x^2 + y^2, u = bx - ay$ and $v = bx + ay$. Then perform the following tests in order until a conclusion is reached:

  1. If $d2 > (D + r)^2$ or $u > r$ or $v < -r$, then the circle does not intersect the sector.
  2. If two or more of the following hold: $d2 \le D^2$, $u \le 0$, $v \ge 0$, then the circle intersects the sector.
  3. If $r < D$ then it is impossible that all three of $d2 > D^2$, $u > 0$, $v < 0$ hold. But at this point, two of them must (otherwise it would have passed condition 2). So we must be near one of the three corners.
    • If $u > 0$ and $v < 0$, then let $(p,q) = (0,0)$.
    • If $u > 0$ and $d2 > D^2$, let $(p,q) = (Da, Db)$.
    • Otherwise (i.e., $d2 > D^2$ and $v < 0$), let $(p,q) = (Da, -Db)$.
  4. Once $(p,q)$ is defined, check if $(x - p)^2 + (y - q)^2 \le r^2$. If so, the circle intersects the segment.
  5. The circle does not intersect the segment.
Paul Sinclair
  • 43,643
  • I have been avoiding this for some time. I'm not so sure, computationally speaking, this is the best approach, because most things that look very complicated when written in "math" turn out to not perform very well when written in "programming". I will try to wrap my head around this as soon as possible. – FinnTheHuman May 24 '17 at 22:51