Let $\theta(\vec p, \vec q, \vec r)$ be the angle theta between 3D real vectors $(\vec{q}-\vec{p})$ and $(\vec{r} - \vec{p})$. What is a simple expression of $\nabla \theta$ in terms of $\vec{p}$, $\vec{q}$, and $\vec{r}$ that is efficient for computation?
The context is that I'm writing a minimization function that operates on a deformable triangle mesh; I would like to use a harmonic angle potential to prevent significant deformation of the angles in the mesh. The potential energy function for this would be $E(\theta) = K (\theta - \theta_0)^2$ and the gradient in terms of $\theta$ is $\nabla E = 2 K (\theta - \theta_0)$ for a constant $K$ and an initial angle $\theta_0$. Finding the form of $\nabla E$ in terms of the vector values is quite trivial with the exception of finding the form of $\nabla \theta$ in terms of the vectors.
It's easy enough to pop this expression into Mathematica and get a monstrous form of the gradient out in terms of $(x_p, y_p, z_p, \; x_q, y_q, z_q, \; x_r, y_r, z_r)$; if I were only calculating this gradient over a few values this would be fine, but I'll be calculating this for hundreds of thousands of angles, and need the calculation to be very efficient. My intuition is that the derivative in terms of $\vec{q}$ or $\vec{r}$ should be orthogonal to $\vec{q} - \vec{p}$ or $\vec{r} - \vec{p}$, respectively, and that the derivative in terms of $\vec{p}$ should be parallel to the angle bisector. This doesn't particularly help me come up with something more efficient, however. I've found numerous resources that talk about this particular problem (here, for example, section on Angle Potential), usually interms of molecular dynamics simulation, but have been unable to find a simple form of the gradient.
Thanks in advance.
I am also looking answer for the same question. So far I am done with below. I am referring to the equation in Gromacs manual for harmonic angle bond. $$ V(\theta_{ijk})=\frac{1}{2}k_{ijk}^\theta (\theta_{ijk}-\theta_{0})^{2} $$ $$ \theta_{ijk}=cos^{-1} \frac{\overrightarrow{r_{ij}}.\overrightarrow{r_{kj}}}{r_{ij}r_{kj}} $$ $$ F_{i}=-\frac{\partial V(\theta)}{\partial r_{i}} $$ $$ F_{i}= -k_{ijk}^\theta.(\theta_{ijk}-\theta_{0}).\frac{\partial \theta_{ijk}}{\partial r_i} $$ $$ \frac{\partial \theta_{ijk}}{\partial r_i}=\frac{-1}{\sqrt{1-u^{2}}}.\frac{\partial u}{\partial r_i} $$ where $$u=\frac{\overrightarrow{r_{ij}}.\overrightarrow{r_{kj}}}{r_{ij}r_{kj}} $$ Now, $$ \frac{\partial u}{\partial r_i}=\frac{1}{r_{ij}r_{kj}}(\overrightarrow{r_{ij}}.\frac{d\overrightarrow{r_{kj}}}{dr_i}+\frac{d\overrightarrow{r_{ij}}}{dr_i}.\overrightarrow{r_{kj}} ) ?? $$ I am stuck in the last part...Anybody with better grip in maths can please point out the missing detail...