Drawing of the vector and line
I have vector points A (Xa, Ya, Za) and B (Xb, Yb, Zb)
Point to measure the distance from; C (Xc, Yc, Zc)
I don't know if it's correct, but this is my equation for distance: D = (|(C-A) * (C-B)|) / (|B-A|)
Can I split that formula to:
Dx = (|(Xc-Xa) * (Xc-Xb)|) / (|Xb-Xa|)
Dy = (|(Yc-Ya ) * (Yc-Yb)|) / (|Yb-Ya|)
Dz = (|(Zc-Za) * (Zc-Zb)|) / (|Zb-Za|)
, to get the X distance, Y distance and Z distance from the point to vector?
If that equation is even correct.
I'm pretty insecure since I'm still in high school and don't know much about 3D math. Would really appreciate if you helped me out or gave me a better solution if there is one. (This is for game programming purposes)
Let $\theta$ be the angle between the vectors $\overrightarrow{AC}$ and $\overrightarrow{AB}$. Then, the distance, i.e. the length of the perpendicular drawn from $C$ to $AB$ is
$$d = \vert\overrightarrow{AC}\vert\sin\theta$$
You also know the cross product
$$ \vert\overrightarrow{AC} \times \overrightarrow{AB}\vert = \vert\overrightarrow{AC}\vert\vert\overrightarrow{AB}\vert\sin\theta $$
therefore
$$ d = \frac{\vert \overrightarrow{AC} \times \vec{AB} \vert}{\vert\vec{AB}\vert} $$
EDIT: To find the perpendicular vector, consider the projection vector of $\overrightarrow{AC}$ on the line $AB$. Let's call this $\overrightarrow{D}$. Then its length is given by
$$ \vert\overrightarrow{AD}\vert = \vert\overrightarrow{AC}\vert\cos\theta = \frac{\overrightarrow{AC}\cdot \overrightarrow{AB}}{\vert \overrightarrow{AB} \vert} $$
where the dot product identity was used. Since $\overrightarrow{AD}$ is in the same direction as $\overrightarrow{AB}$, you can find its coordinates by "scaling" $\overrightarrow{AB}$, i.e.
$$ \overrightarrow{AD} = \vert \overrightarrow{AD} \vert \frac{\overrightarrow{AB}}{\vert\overrightarrow{AB}\vert} = \frac{\overrightarrow{AC}\cdot \overrightarrow{AB}}{\vert \overrightarrow{AB} \vert^2} \overrightarrow{AB}$$
The perpendicular vector, $\overrightarrow{DC}$, is computed by the difference
$$ \overrightarrow{DC} = \overrightarrow{AC} - \overrightarrow{AD} $$
The 3 components of $\overrightarrow{DC}$ are the $x$, $y$, $z$ distances you're looking for.