Rotation of a point around an axis using the cartesian coordinates

3dcoordinate systemsrotationstrigonometry

I'm looking for the formula to calculate the cartesian coordinates of a point A(Xa, Ya, Za) after a rotation of an angle δ (in radians) around an axis B(Xb, Yb, Zb)C(Xc, Yc, Zc).

I found how to do it using rotation matrices or quaternions.
But how can I do that using the cartesian coordinates of the A, B and C points?

Best Answer

$\newcommand{\Vec}[1]{\mathbf{#1}}$Here is an algorithm (not a formula per se, but can be turned into one):

  1. Calculate the unit vector $\Vec{e}_{3} := \dfrac{C - B}{\|C - B\|}$.
  2. Pick (or calculate) a unit vector $\Vec{e}_{1}$ perpendicular to $\Vec{e}_{3}$. (There is no continuous way to do this using $\Vec{e}_{3}$, but see note below.)
  3. Put $\Vec{e}_{2} = \Vec{e}_{3} \times \Vec{e}_{1}$ and \begin{align*} \Vec{e}_{1}' &= \phantom{-}(\cos\delta) \Vec{e}_{1} + (\sin\delta) \Vec{e}_{2}, \\ \Vec{e}_{2}' &= -(\sin\delta) \Vec{e}_{1} + (\cos\delta) \Vec{e}_{2}. \end{align*}
  4. Let $v = A - B$. The desired point is $$ A' = B + (v \cdot \Vec{e}_{1})\Vec{e}_{1}' + (v \cdot \Vec{e}_{2})\Vec{e}_{2}' + (v \cdot \Vec{e}_{3})\Vec{e}_{3}. $$

Geometrically, $(\Vec{e}_{1}', \Vec{e}_{2}', \Vec{e}_{3})$ is the result of rotating the "original" orthonormal basis $(\Vec{e}_{1}, \Vec{e}_{2}, \Vec{e}_{3})$ through angle $\delta$ about $\Vec{e}_{3}$. The formula in item 4. decomposes $A - B$ (the displacement of point $A$ from the "origin" $B$) into components with respect to the original basis, and uses those as components with respect to the rotated basis.

Rotating a vector about an axis in three-space

Note: If $\Vec{e}_{3} = (0, 0, \pm 1)$ we can pick $\Vec{e}_{1} = (1, 0, 0)$ and $\Vec{e}_{2} = (0, 1, 0)$. Otherwise, we have $\Vec{e}_{3} = (X, Y, Z)$ with $X^{2} + Y^{2} \neq 0$, and may pick $$ \Vec{e}_{1} = \frac{(-Y, X, 0)}{\sqrt{X^{2} + Y^{2}}}. $$ This is not numerically robust if the segment $\overline{BC}$ is nearly parallel to the third Cartesian axis. In practice, find the two largest (in absolute value) components of $\Vec{e}_{3}$ and pick $\Vec{e}_{1}$ using those instead of the first two.