Intersection of any function and a circle I wanted to know how to find a specific angle based on a function and a circle intersection.
To understand, you first need to see the drawing : 

What I want is to find the smaller alpha angle possible value where the arc-circle drawn by this angle 'cut' a random function. The origin of the circle is $O(0, 0)$ and the radius is $1$ (but I don't think the radius would impact the calcul).
I first thought about how I could find this angle if the function was linear: $y=ax+b$.
When $a \ne 0$ there are some equations :


*

*$ax + b = 0$

*$x^2+y^2=R^2$ (with R the circle radius)

*$\cos{\alpha}=x$

*$\sin{\alpha}=f(x)$
and the solutions are :
$$x = {-ab \pm \sqrt{-b^2+R^2+a^2R^2} \over 1+a^2}.$$
This worked with $R = 1$. You just have to set $\alpha=\arccos{x}$.
So I thought about guessing the intersection between the tangent of the function at the value $a.$
This gave me two equations : $y=f(x)$ and $x^2+y^2=R^2.$
The first gives that  tangent line : $y = xf'(x)+(f(a)-f'(x)a)$.
So I solved the same system and found :
$$x = {-f'(x)[f(a)-f'(x)a] \pm \sqrt{-[f(a)-f'(x)a]^2+R^2+f'(a)^2R^2} \over 1+f'(a)^2}.$$
This equation is true when $f(x) = ax + b$, because if you replace everything by those values, you get the previous correct equation.
But this new $x$ value is not right and I don't know why....
Maybe there is an easier way to solve my problem... Anyway thanks for trying helping me :).
Edit 1 : An algorithm will do the job too if the mathematical solution is too hard to find (I'm using Java).
Edit 2 : So, since there is an infinite number of possibilities which may answer the question as impossible, do you think there is an algorithm capable to find that angle ?
 A: Since your function $f(x)$ is arbitrary, it can intersect the circle at infinitely many points. That is, you have no guarantee of getting a single root. To see this you can try plugging in $(x,f(x))$ in the general circle equation (with center $(c_x,c_y)$ and radius $R$):
$$(x-c_x)^2 + (f(x)-c_y)^2 = R^2$$
$$x^2 -2c_xx + f^2(x) - 2c_yf(x) + c_x^2 + c_y^2 - R^2 = 0$$
$$g(x) = 0$$
Note that depending on the form of $f$, the equation above may have infinitely many roots. Take as an example: $f(x) = c_y + \chi_{[-1,1]}(x)\sqrt{R^2(1-(x-c_x)^2)}$. It coincides with the upper half of the circle, so there's no plausible solution to your problem in that case. You will have to specify a certain class of functions $F$ for which your problem makes sense.
Edit: On the other hand, if you already have an intersection point at some $(x_0,y_0)$, then the only thing you really need to do is use $\tan\alpha = \frac{y_0-c_y}{x_0 - c_x}$, and then invert it to get $\alpha$. In programming math libraries (C++ for example) there's usually a function called $atan2$ that also takes the signs of the numerator and denominator into account to produce the correct angle. Refer to: https://en.wikipedia.org/wiki/Atan2
A: Recast the question in polar coordinates.
You are looking for the point that satisfies
$$x^2+f^2(x)=1$$
while it minimizes
$$\arctan\frac{f(x)}x.$$
Except for a few specific cases (linear or quadratic polynomial, homography and a few others), the root of the first equation don't have a closed-form expression and you will need to resort to numerical methods.
Unfortunately, there is no general numerical method that can guarantee to find the "first" solution. You need to exploit some known property of $f$.
