# Circles, where do you meet?

Given 2 random circle sections, return how many times they intersect. Rules/clarifications are as below.

1. You are provided 10 total values,
• The center (x,y) of the circle section
• Angles of the circle (i.e. (0,90) would be a quarter circle "facing" the top-right corner.
• The radius of the circle section
2. The circle sections are "drawn" on a 128 by 128 screen, with (0,0) being the center. They have a max radius of 64.
3. You don't need to draw the circles - the program should only print out the number of intersections.
4. You can choose to generate the values randomly, in-program, or have the user write it in at program start. (The latter is preferred, but not necessary.)

Below is an example case. As you can see, it has one intersect. The output should look something like this:

$run ./circle input (circle 1 center) input (circle 1 radius) input (circle 1 angles) input (more inputs...) ... intersections  Heres the output for the example case (the prompts are optional): $ run ./circle
c1center: (20,20)
c1angles: (210,150)
c2center: (-30,-30)
c2angles: (270,180
1


Anyway, best of luck! This is code golf, so the minimum number of bytes in any programming language wins!

Oh, and it'd be nice if you could provide a description/link to your program in the answer. Standard Loopholes are not allowed. If you find any errors in my explanation or want me to clarify, just ask. Thanks!

• May we assume that the circles are distinct so that there are not infinite intersections? Dec 13, 2017 at 2:15
• @notjagan yes, circles are completely different in that respect.
– i..
Dec 13, 2017 at 2:16
• What if the intersection is outside the monitor/screen? Dec 13, 2017 at 2:41
• @user202729 It should be counted - only the center of the circles themselves need to be on-screen. I hope this helps.
– i..
Dec 13, 2017 at 3:41
• Note that challenges should be completely clear since it was posted, because edits to the question may validate existing answers. That's a common mistake with challenges of new users. To achieve that, using the Sandbox is often helpful. Dec 13, 2017 at 3:59

# Python 3 + numpy, 310 291 bytes

-19 bytes thanks to ovs!

v=lambda c,x,y:sin(arctan2(*c[::-1])-x)>sin(y-x)
def f(a,r,w,x,b,s,y,z):
d=linalg.norm(b-a)
if abs(r-s)<d<r+s:e=(r*r-s*s+d*d)/2/d;g=a+e*(b-a)/d;t=(sqrt(r*r-e*e)*(b-a)/d*[1,-1])[::-1];return int(v(g+t-a,w,x)and v(g+t-b,y,z))+int(v(g-t-a,w,x)and v(g-t-b,y,z))-(t==0).all()
from numpy import*


Try it online!

• 291 bytes, no need to convert bool to int, a%(2*pi)<b%(2*pi) is equivalent to sin(a)>sin(b) ...