Given two points $P$ and $Q$, a line ($A$, $B$ - orthogonal projection of $P$, $Q$ onto the line) and a coefficient $n$, I want to find out such point $C$ that $\frac{\sin{a}}{\sin{b}}=n$ (in fact, it's an equation of light refraction). I also assume that $C$ lies between $A$ and $B$. See the image below:
What I know is: $w, h, d, n$. What I want to calculate is $x$.
I need to find the easiest solution possible, in order to calculate $x$ in a computer's application very efficiently.
What I've found out so far is:
$n=\frac{\sin{a}}{\sin{b}}=\frac{\frac{d-x}{\sqrt{(d-x)^2+w^2}}}{\frac{x}{\sqrt{x^2+h^2}}}=\frac{(d-x)\sqrt{x^2+h^2}}{x\sqrt{(d-x)^2+w^2}}$
Hence, we need to solve this equation for $x$ (assuming $0
$n^2x^2((d-x)^2+w^2)=(d-x)^2(x^2+h^2)$
which yields:
$f(x)=(n^2-1)x^4-2d(n^2-1)x^3+((d^2+w^2)(n^2-1)+w^2-h^2)x^2+2dh^2x-d^2h^2 = 0$
That way we obtained a quartic equation. How to solve it? I've tried using the Ferrari's solution, but the result is very complicated. Moreover, this equation can have as many as four real roots but I know it's got only one root for $0