# Applying the rotation between $\vec{a}$ and $\vec{b}$, to vector $\vec{c}$

Given 3 unit vectors $\vec{a}$, $\vec{b}$, and $\vec{c}$ in $\mathbb{R}^3$.

I would like to compute the rotation between $\vec{a}$ and $\vec{b}$.

Then apply that rotation to $\vec{c}$ to obtain a new vector $\vec{d}$.

$\vec{c}$ is not coplanar with $\vec{a}$ and $\vec{b}$.

I attempted this with both rotation matrices and quaternions, computing the rotation between $\vec{a}$ and $\vec{b}$, but when I apply it to $\vec{c}$ the dot product is not equal, e.g.:

$\vec{a} \cdot \vec{b} \ne \vec{c} \cdot \vec{d}$

Because $\vec{c}$ is not coplanar with $\vec{a}$ and $\vec{b}$.

Should I compute the rotation for each axis independently and then recombine them? I'm not sure what the correct approach is here.

Context:

I'm trying to correlate the rotation from the center pixel of an image $\vec{a}$ to a point of interest on the image $\vec{b}$. Given that I know the cameras focal length I can compute the unit vectors in pixel space. I have the cameras angle of focus in world coordinates $\vec{c}$ and want to angle the camera by the same amount such that it is pointing directly at the point of interest, new vector $\vec{d}$

• In general there are an infinite number of 3-dimensional rotation transformations that will take $\vec a$ to $\vec b$, so you have to specify some other constraint. What exactly are you trying to do here? – Carmeister Aug 19 '17 at 21:00
• @Carmeister That is true, but there is one rotation which stands out: $\vec a$ and $\vec b$ define a plane, and if the rotation is around the normal vector of that plane, then it's unique. – Arthur Aug 19 '17 at 21:06
• I'm trying to correlate the rotation from the center pixel of an image $\vec{a}$ to a point of interest on the image $\vec{b}$, given that I know the cameras focal length I can compute the unit vectors. I have the cameras angle of focus in world coordinates $\vec{c}$ and want to angle the camera by the same amount such that it is pointing directly at the point of interest, new vector $\vec{d}$. – David Parks Aug 19 '17 at 21:07
• It would be advisable to put this bit of context into your question. It makes it more interesting for people to answer (and adding context might stop the infantile close-zealots, though I wouldn't wager large sums on that). – Professor Vector Aug 19 '17 at 21:58
• If I’ve understood what it is you’re trying to accomplish correctly, then you just need to transform the computed rotation axis back into world coordinates. – amd Aug 19 '17 at 22:44

Of course, you use Rodrigues rotation formula. I'm pretty certain there's an equivalent quaternion formulation, but... well, I'm not Professor Quaternion. =D In this case, $\alpha$ and $\theta$ are equal, and since $\vec{a}$ and $\vec{b}$ are unit vectors, we have $\sin\theta=|\vec{a}\times\vec{b}|$ and $\cos\theta=\vec{a}\cdot\vec{b}$, giving the final result $$\vec{d}=(\vec{a}\cdot\vec{b})\,\vec{c}+|\vec{a}\times\vec{b}|\,\vec{k}\times\vec{c}+(1-\vec{a}\cdot\vec{b})\,(k\cdot\vec{c})\,\vec{k},$$ where $$\vec{k}=\frac{\vec{a}\times\vec{b}}{|\vec{a}\times\vec{b}|}$$ is your (normalized) axis of rotation.
Edit: the formulation $$\vec{d}=(\vec{a}\cdot\vec{b})\,\vec{c}+(\vec{a}\times\vec{b})\times\vec{c}+\frac{((\vec{a}\times\vec{b})\cdot\vec{c})\,\vec{a}\times\vec{b}}{1+\vec{a}\cdot\vec{b}}$$ avoids the problem worrying @John Huges... but it doesn't resolve another one: $\vec{a}=-\vec{b}$. In that case, it's really not clear what should happen.
• This approach seems to have the same problem that I've encountered with my other attempts. I think the axis of rotation applied to $\vec{c}$ is incorrect (I'm still tring to wrap my head around this). When I apply this $\vec{a} \cdot \vec{b} \ne \vec{c} \cdot \vec{d}$ Using $a=[0.58,0.58,0.58]$, $b=[0,0,1]$, $c=[0,1,0]$ I get $d=[-0.21, 0.79, 0.58]$ whereas I think I should be expecting $[-0.58, 0.58, 0.58]$ based on a visual inspection. – David Parks Aug 19 '17 at 22:04
• @David Parks That's true, you could have $\vec{a} \cdot \vec{b} = \vec{c} \cdot \vec{d}$ only if $\vec{c}$ were coplanar with $\vec{a}$ and $\vec{b}$. But what I wrote is the result if you rotate $\vec{c}$ around the same axis (not perpendicular to $\vec{c}$, then). So I suspect the operation you want isn't exactly the rotation you describe. – Professor Vector Aug 19 '17 at 22:15
• I believe you're right, I am not describing the rotation correctly, I fear that I don't know what I don't know still. Ultimately I want the change between $\vec{a}$ & $\vec{b}$ that occurs when I compute vectors in pixel space (I see a point of interest on the screen) to apply in world space (the camera now physically points at that point of interest based on its screen coordinates). – David Parks Aug 19 '17 at 22:52