Rotate Vector to Connect Points Give the $[x,y,z]$ cords for two points and a line-segment. The length of the line-segment is equal to the distance between the points, and the midpoint of the segment is at the midpoint of the line between the two points. The line-segment is along the $y$-axis, i.e magnitude $[0, 1, 0]$
How would you calculate the axis about an angle by which to rotate the line-segment such that after the rotation its ends are touching the two points?
 A: We are given:
$\vec{P1}$, $\vec{P2}$, and $\vec{segment}$. Also that the midpoint of $\vec{segment}$ and midpoint of the line connecting $\vec{P1}$, $\vec{P2}$ are the same point.
Here is how I solved it:
$$\vec{connect} = \vec{P1} - \vec{P2}$$
We'll want to rotate $\vec{segment}$ in the plane span by $\vec{segment}$ and $\vec{connect}$ ie the only plane that they are both in (coplanar). This is how we will get $\vec{segment}$ and $\vec{connect}$ to be colinear, our goal. Another way to say this is we will want to rotate $\vec{segment}$ about a vector normal to this plane, or to both $\vec{segment}$ and $\vec{connect}$. Such a vector is found using the cross product.
From the definition of cross product:
$$\vec{axisOfRotation} = \vec{connect}\times\vec{segment}= |\vec{connect}||\vec{segment}|\sin{\theta} \hat{n}$$
so
$$|\vec{axisOfRotation}| = |\vec{connect}\times\vec{segment}|= |\vec{connect}||\vec{segment}|\sin{\theta}$$
thus
$$\theta = \arcsin{\frac{|\vec{axisOfRotation}|}{|\vec{connect}||\vec{segment}|}}$$
I used the math.js library to find $\vec{axisOfRotation}$ but the calculations isn't hard to do. I was able to perform a rotation about $\vec{axisOfRotation}$ by the amount $\theta$.
