7. In the Cartesian coordinate plane, the 4 points $A(1,2)$, $B(3,1)$, $C(2,3)$, $D(4,0)$ have a sum of the squares of their distances to the line $y=kx$ denoted as $S$. When $k$ varies, the minimum value of $S$ is $\qquad$
$7.22-\sqrt{185}$.
Let the distances from points $A$, $B$, $C$, and $D$ to the line $k x-y=0$ be $d_{1}$, $d_{2}$, $d_{3}$, and $d_{4}$, respectively. Then
$$
\begin{array}{l}
d_{1}=\frac{|k-2|}{\sqrt{k^{2}+1}}, d_{2}=\frac{|3 k-1|}{\sqrt{k^{2}+1}}, \\
d_{3}=\frac{|2 k-3|}{\sqrt{k^{2}+1}}, d_{4}=\frac{|4 k|}{\sqrt{k^{2}+1}} \text {. } \\
\text { Therefore, } S=\frac{(k-2)^{2}+(3 k-1)^{2}+(2 k-3)^{2}+(4 k)^{2}}{k^{2}+1} \\
=\frac{30 k^{2}-22 k+14}{k^{2}+1} \text {. } \\
\end{array}
$$

Thus, $(30-S) k^{2}-22 k+(14-S)=0$.
When $S=30$, $k=-\frac{8}{11}$.
When $S \neq 30$,
$$
\Delta=22^{2}-4(30-S)(14-S) \geqslant 0 \text {. }
$$

Solving this, we get $22-\sqrt{185} \leqslant S \leqslant 22+\sqrt{185}$,
When $S=22-\sqrt{185}$, $k=\frac{11}{8+\sqrt{185}}$.

Since $22-\sqrt{185}<30$, the minimum value of $S$ is $22-\sqrt{185}$.