I have been battling a problem of needing to know the derivative of the angle between two vectors, the vectors possibly being parallel at some points in time. I started off with:
$$\bf A \dot \bf B = \|A\|\|B\|\cos\theta \Rightarrow \theta=\arccos \left( \frac{\bf A \dot \bf B}{\|A\|\|B\|} \right)$$
Let's say that $\bf A$ and $\bf B$ are unit vectors for simplicity so:
$$ \theta=\arccos \left( \bf \hat A \dot \bf \hat B \right) $$
To find the derivative of the angle $\theta$:
$$ \dot \theta = \frac{-1}{\sqrt{1-\left(\bf \hat A \dot \bf \hat B\right)^2}} \left[\bf \dot{\hat A}\dot \bf \hat B+\bf {\hat A}\dot \bf \dot{\hat B}\right] $$
But, $\bf{\hat A} \dot \bf{\hat B}=$$1$ when $\bf \hat A \,\,\|\,\, \bf \hat B$ and the denominator of the expression for $\dot \theta$ becomes $0$. We hence get a division by $0$. Now I have tried other ways - by projecting $\bf{\hat B}$ onto $\bf{\hat A}$ and taking $\arctan$, by projecting $\bf{\hat B}$ onto a plane and forming a right-angle triangle and again taking $\arctan$. Every method I tried leads to the same singularity when $\bf \hat A \,\,\|\,\, \bf \hat B$.
Question: what method can I use such that I don't get a singularity for $\dot\theta$ when $\bf{\hat A}$ becomes parallel to $\bf{\hat B}$? Thank you!
Consider the function $F:\mathbb R^n \setminus\{0\} \to \mathbb S_{n-1}$, defined by $F(u) := u/\|u\|$. So you seek $\dot\theta(t)$, where $\theta(t):= \arccos(r(t))$, and $r(t): = a(t)\cdot b(t)$, where $a(t):= F(x(t))$ and $b(t) := F(y(t))$
Now, by chain rule, $\dot{r}(t) = a(t).\dot{b}(t) + \dot{a}(t)\cdot b(t)$. Using a algebraic fact (see lemma below) and the chain rule again, we get $$ \begin{split} \dot{a}(t) &= \nabla F(x(t))\cdot\dot{x}(t) = \frac{I_n-F(x(t))\otimes F(x(t))}{\|x(t)\|}F(y(t)),\\ \dot{b}(t) &= \nabla F(y(t))\cdot\dot{y}(t) = \frac{I_n-F(y(t))\otimes F(y(t))}{\|y(t)\|}F(x(t)), \end{split} $$ where $\otimes$ denotes the outer-product of vectors (produces a rank-1 matrix) and $I$ is the identity matrix of size $n$. Putting everything together should give you the correct formula for $\dot{r}(t)$. Now by using the chain rule one last time to get $\dot{\theta} = -\dfrac{1}{\sqrt{1-r(t)^2}}\dot{r}(t)$.
Proof. Chain rule and basic matrix calculus.