This seems to me as a very simple and basic question, though I'm having trouble with it.
The Problem
Given a sphere $K\in\mathbb{R}^n$ with radius $r\in\mathbb{R}$ and center $\vec{c}\in\mathbb{R}^n$: $$K:||\vec{x}-\vec{c}||_2^2=r^2$$
And a given line along $\vec{n}\in\mathbb{R}^n$, $||\vec{n}||_2=1$ through $\vec{x}\in\mathbb{R}^n$: $$g: \vec{x}+\vec{n}d$$
Substituting the line into the equation of $K$ gives $$||\vec{x}+\vec{n}d-\vec{c}||_2^2=r^2$$ which results in the quadratic equation $$\sum_{i=1}^{n}(x_i+n_id-c_i)^2-r^2=0$$
Within my problem, it is ensured, that the supporting vector $\vec{x}$ of the line is always within the sphere. With my understanding, this simplifies the solutions of the quadratic equation in such a way, that there are always two solutions for $d$.
The Question
And this is the point, where I got stuck. How can this be rewritten either by using the quadratic formula ($ax^2+bx+c=0 \Rightarrow x_{1,2}=\frac{-b\pm\sqrt{b^2-4ac}}{2a^2}$) or as a system of equations?
Any help is appreciated. Thank you.
$$\sum_{i=1}^{n}(x_i+n_id-c_i)^2-r^2=0$$
$$d^2\sum_{i=1}^{n}n_i^2+2d\sum_{i=1}^{n}n_i(x_i-c_i)+\sum_{i=1}^{n}(x_i-c_i)^2-r^2=0$$
Now you can solve for $d$.
If you're familiar with dot product the whole thing can be simplified. $$(\vec nd+\vec x- \vec c).(\vec nd+\vec x- \vec c)=r^2$$
$$d^2 \vec n.\vec n + 2d\vec n.(\vec x-\vec c)+(\vec x-\vec c).(\vec x-\vec c)=r^2$$
$$d^2 \|\vec n\|^2 + 2d\vec n.(\vec x-\vec c)+\|\vec x-\vec c\|^2=r^2$$