Rotate one 3D vector into another 3D vector along a specified direction I'm trying to figure out what the angle of rotation (sign included) is when you take one 3D vector and rotate it into another 3D vector specifically when the axis of rotation is specified.
The image below shows what I'm trying to do (sorry for my rudimentary hand drawing). The angle theta is what I'd like to calculate.
Say there's a 3D vector v that defines the axis of rotation. Imagine a plane that includes both vector v and point p1, then we rotate this plane about the axis v until it hits point p2. The rotation of this plane forms the angle theta which is what I'm trying to compute. Note that vector v is not necessarily parallel to the cross product of p1 and p2. The origin o in my case is just (0,0,0)

 A: If I'm understanding correctly, you want find the angle needed to rotate the plane containing both $v$ and $p_1$ until that plane contains $p_2$.
If $p_1\times p_2 = \lambda v$, the angle is simply $\theta(p_1,p_2) = \dfrac{p_1\cdot p_2}{|p_1||p_2|}$.
To make this work for the case where $p_1\times p_2 \neq \lambda v$, we can instead use $\theta(p_1,\hat p_2)$, where $\hat p_2$ is the projection of $p_2$ into the plane containing $p_1$ with normal $v$. Doing this gives us
$$\hat p_2 = p_2 - (v\cdot(p_2-p_1))v$$
(See this question if you're confused about this step)
Note that the rotated point $p_1'$ is a scaled $\hat p_2$, in particular
$$ p_1' = \frac{|p_1|}{|\hat p_2|}\hat p_2 $$
A: Let $\mathbf{x}$ be the vector to be rotated, $\mathbf{x}'$ the rotated vector, $\mathbf{n}$ the unit axis vector ($||\mathbf{n}||=1$) and $\theta$ the rotation angle. The rotated vector then equals to $\mathbf{x}'=\mathbf{R}\mathbf{x}$, where
\begin{align} \mathbf{R}=\mathbf{I}+\sin\theta\mathbf{N}+2\sin^2(\theta/2)\mathbf{N}^2,~\mathbf{N}=\textbf{Spin}(\mathbf{n})=\left[
 \begin{array}{ccc}
  0         & -n_3 & n_2\\
  n_3  & 0         &-n_1 \\
  -n_2 & n_1  & 0 \\
 \end{array}
 \right] 
\end{align}
Example:
\begin{align}
\mathbf{n}&=\left[
\begin{array}{c}
 0\\
 0\\
 1\\
\end{array}
\right],~\mathbf{x}=\left[
\begin{array}{c}
 1\\
 0\\
 0\\
\end{array}
\right],~\theta=\frac{\pi}{2}\\&\implies\mathbf{N}=\left[
\begin{array}{ccc}
 0 & -1 & 0\\
 1 & 0 &0 \\
 0 & 0 & 0 \\
\end{array}
\right],~\mathbf{N}^2=\left[
\begin{array}{ccc}
 -1 & 0 & 0\\
 0 & -1 &0 \\
 0 & 0 & 0 \\
\end{array}
\right],~\mathbf{x}'=\left[
\begin{array}{c}
\frac{\sqrt{2}}{2}\\
\frac{\sqrt{2}}{2}\\
 0\\
\end{array}
\right]
\end{align}
A: Just a variation of the above answer.
Project both vectors $p_1$ and $p_2$ onto the plane perpendicular to vector $v$.
It is the plane where rotation acts.
Asumming $v$ is unit vector we have
$v_1= (I-vv^T)p_1$
$v_2= (I-vv^T)p_2$
Now just calculate the angle between $v_1$ and $v_2$ using scalar product.
$v_1^Tv_2=\Vert v_1 \Vert \Vert v_2 \Vert \cos \theta $.
A: Ended up finding the solution myself, so wanted to post what I came up with. Turned out to be a little more simple than I realized.
First compute a normal vector to the plane formed by v and p1 and also the plane formed by v and p2
n1 = ||v X p1||
n2 = ||v X p2||

Then I can take these two vectors and compute the angle between them by doing
abs_theta = arccos(n1 * n2)

This gives me the absolute value of the angle I'm searching for
To get the sign of the rotation I need to compute the cross product of n1 with n2
v1 = ||n1 X n2||

and dot it with v
sign = ((v * v1) > 0) * 2 - 1

sign = 1 if positive rotation and sign = -1 for negative rotation
Note: Some final logic is needed to take care in the special situation's of theta = 0 or 180
Here's a simple Matlab script that does the math. Messing around with the z value of p2 doesn't change the computed angle, which is what I was looking for.

