Closest point on a line segment to the x-axis Knowing the (x,y,z) coordinates of the two endpoints of a line segment in 3D space, how can I calculate the point on the line segment that is a minimum distance to the x-axis?
EDIT: Assume it is known that neither endpoint of the line segment is the closest point, so we must calculate which point along that line segment is closest. 
I see many examples of calculating the minimum distance from a line to a point, but I am not sure how to modify it for my use case.  
Thank you.
 A: Answering edited question (original answer to original question follows):
The distance of a point from the x-axis is $\sqrt{y^2+z^2}$, so it suffices to minimize $y^2+z^2$.  A line can be parameterized as $(x,y,z)=(f(t),g(t)h(t))$ for linear $f, g, h$.  You need to minimize $g(t)^2+h(t)^2$, which is a quadratic polynomial in $t$ and thus an easy calculus problem.

Answer to original question:
Find the minimum distance from the line to the x-axis--and also the minimizing point P.  If P is on your line segment, that's the answer.
Otherwise check the distance of the endpoints of the line segment from the x-axis.  Whichever of those is closer, that's then the answer.
Justification is that this is a convex problem, so there's a unique local minimum along the line, which is also a global minimum.  So on any closed interval, if the global minimum isn't in the interval, the minimum for that interval is at an endpoint.
The exceptional case would be the line could be parallel to the x-axis.  Then any point on the segment would have the same distance, so that would be easy to diagnose.  (Not to mention the formula for the line being (x,y,z)=(t,C,D) would be a dead giveaway...)
A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

The line segment is parametrized as
  $\ds{\vec{p}_{0} + \mu\Delta\vec{p}}$ where $\ds{\vec{p}_{0}\ \mbox{and}\ \vec{p}_{0} + \Delta\vec{p}}$ are the end points and $\ds{0 \leq \mu \leq 1}$. The $\ds{x}$-axis is parametrized as $\ds{\nu\hat{x}}$. The distance between a given point in the segment and a givent point $\ds{\nu\hat{x}}$ in the
  $\ds{x}$-axis is given by
  \begin{equation}
\mrm{d}\pars{\mu,\nu} \equiv
\verts{\vec{p}_{0} + \mu\Delta\vec{p} - \nu\hat{x}}
\label{1}\tag{1}
\end{equation}
  So, you can minimize $\ds{\mrm{d}^{2}\pars{\mu,\nu}}$ respect $\ds{\mu\ \mbox{and}\ \nu}$ with the condition $\ds{\mu \in \bracks{0,1}}$:  

\begin{align}
\mrm{d}^{2}\pars{\mu,\nu} & \equiv
\bracks{\pars{\vec{p}_{0} + \mu\vec{p}_{1}} - \nu\,\hat{x}}^{2} =
p_{0}^{2} + \mu^{2}p_{1}^{2} + \nu^{2} + 2\vec{p}_{0}\cdot\vec{p}_{1}\mu -2p_{0x}\nu -2p_{1x}\mu\nu
\\[5mm]
0 & = \partiald{\,\mrm{d}^{2}\pars{\mu,\nu}}{\mu} =
2\mu p_{1}^{2} + 2\vec{p}_{0}\cdot\vec{p}_{1} - 2p_{1x}\nu\,,\qquad
0 = \partiald{\,\mrm{d}^{2}\pars{\mu,\nu}}{\nu} =
2\nu - 2p_{0x} - 2p_{1x}\mu 
\\[5mm]
&\left.\begin{array}{rcrcl}
\ds{p_{1}^{2}\mu} & \ds{-} & \ds{p_{1x}\nu} & \ds{=} & \ds{-\vec{p}_{0}\cdot\vec{p}_{1}}
\\[1mm]
\ds{p_{1x}\mu} & \ds{+} & \ds{\nu} & \ds{=} & \ds{{p}_{0x}} 
\end{array}\right\}\qquad
\pars{\begin{array}{ll}
\ds{\left. 1\right)} &
\mbox{Find}\ \ds{\mu}\ \mbox{and}\ \ds{\nu}\ \mbox{from those equations.}
\\[2mm]
\ds{\left. 2\right)} &
\mbox{If}\ \ds{\mu \in \bracks{0,1}},\ \mbox{the answer is given}
\\ & \mbox{by evaluation of}\ \eqref{1}\ \mbox{with the values}
\\ & \mbox{of}\ \ds{\mu}\ \mbox{and}\ \ds{\nu}\ \mbox{you already found in}\
\ds{\left. 1\right)}.
\\[2mm]
\ds{\left. 3\right)} & 
\mbox{If}\ \ds{\mu \not\in \bracks{0,1}},\ \mbox{the answer is given}
\\ & \mbox{by}\ \ds{\min\braces{\mrm{d}\pars{0,\nu},\mrm{d}\pars{1,\nu}}}.
\end{array}}
\end{align}
