How would I find the angle between point A(x1, y1, z1) and point B(x2, y2, z2) not taken from the origin, but from another point C(x3, y3, z3)? In other words, what would the measure of the angle ACB be, while still preserving the variables?
Thank you in advance.
For anyone else wondering about this, here's the entire procedure.
First, you calculate the two vectors whose angle you are interested in; $\vec{u} = \overline{C A}$ and $\vec{v} = \overline{C B}$ in this particular case: $$\vec{u} = \left [ \begin{matrix} x_1 - x_3 \\ y_1 - y_3 \\ z_1 - z_3 \end{matrix} \right ], \quad \vec{v} = \left [ \begin{matrix} x_2 - x_3 \\ y_2 - y_3 \\ z_2 - z_3 \end{matrix} \right ]$$ The angle between these two vectors is $\theta$: $$\left\lbrace ~ \begin{aligned} \cos\theta &= \frac{\vec{u} \cdot \vec{v}}{\left\lVert\vec{u}\right\rVert \left\lvert\vec{v}\right\rVert} \\ \sin\theta &= \frac{\left\lVert\vec{u}\times\vec{v}\right\rVert}{\left\lVert\vec{u}\right\rVert \left\lvert\vec{v}\right\rVert} \\ \end{aligned} \right.$$ where $\cdot$ denotes dot product, $\times$ cross product, and $\left\lVert \vec{p} \right\rVert = \sqrt{\vec{p}\cdot\vec{p}}$ vector magnitude or Euclidean length.
If you want to do the calculation in a numerically efficient manner, calculate the product of the vectors' Euclidean lengths first: $$d = \sqrt{\bigr( (x_1 - x_3)^2 + (y_1 - y_3)^2 + (z_1 - z_3)^2 \bigr)\bigr( (x_2 - x_3)^2 + (y_2 - y_3)^2 + (z_2 - z_3)^2 \bigr)}$$ If $d$ is very close to zero, say $d \le \epsilon^2$, where $\epsilon$ is the largest coordinate value you'd round to zero, the vectors are too short for the angle to have any meaning. (That is, the product of their lengths is zero using the precision you use for their coordinates.)
Assuming $d$ is not too small, the cosine of angle $\theta$ is $$\cos\theta = \frac{(x_1 - x_3)(x_2 - x_3) + (y_1 - y_3)(y_2 - y_3) + (z_1 - z_3)(z_2 - z_3)}{d}$$ Note that $-1 \le \cos\theta \le +1$, with $\cos 180^o = -1$, $\cos 90^o = 0$, and $\cos 0^o = +1$. This means that if you are comparing the angle between the two vectors to some limiting angle, you do not need to bother calculating the angle itself: you can compare the angles cosines instead (pre-calculating the cosine of the limiting angle, of course).
Mathematically speaking, if $0^o \le \theta \le 180^o$ and $0^o \le \varphi \le 180^o$, then $$\begin{aligned} \theta \lt \varphi \quad &\iff \quad \cos\theta \gt \cos\varphi \\ \theta = \varphi \quad &\iff \quad \cos\theta = \cos\varphi \\ \theta \gt \varphi \quad &\iff \quad \cos\theta \lt \cos\varphi \\ \end{aligned}$$ In computer computation in particular, trigonometric functions (like $\cos$ and $\operatorname{arccos}$) take much longer to compute than basic algebraic operators like addition, subtraction, or multiplication. Division takes usually slightly longer than addition, subtraction, or multiplication; square root, exponent, and logarithm slightly longer; and trigonometric functions like $\sin$, $\cos$, $\tan$ even longer still. In normal computation it does not matter, but something like a game engine or simulator probably should consider that.