Quaternion for beginner

Solution 1:

You can't actually rotate one point about another point, thats not what quaternions do. However, you can rotate a point (P1 in the picture or B in your question) about a rotation axis (which is your A) as shown:

Rotation

1. Constructing the Rotation Quaternion

If you want to achieve a 30 degree rotation, you first need to construct the quaternion that applies the rotation to your point. To do this, first find a unit vector in the direction of A, which is given by:

$$ \hat a = {\vec A \over \left | A \right| } = a_x \hat i + a_y \hat j + a_z \hat k$$

Assuming you now have a unit vector, and want to achieve a 30 degree rotation, you can set $\theta = 30\deg$ and find the quaternion that applies this rotation with:

$$ q = \cos \left( {\theta \over 2} \right) + \hat a\sin \left( {\theta \over 2} \right)$$

At this stage, you will have a single quaternion which has a real component ($\cos \left( {\theta \over 2} \right)$) and an imaginary component, which is the three coefficients from your unit vector multiplied by ($\sin \left( {\theta \over 2} \right)$).

2. Applying the Rotation

Given that the point you are rotating is $B = b_x \hat i + b_y \hat j + b_z \hat k$, you can imagine this as the purely imaginary quaternion:

$$p = b_x i + b_y j + b_zk $$

Now you apply the conjugation formula (which rotates your point p), to this point to get your new point, which we can call $p_\text{new}$, which is given by:

$$p_\text{new} = qpq^{-1}$$

Where $q^{-1} = \cos \left( {\theta \over 2} \right) - \hat a\sin \left( {\theta \over 2} \right)$. Then the complex part of $p_\text{new}$ is your rotated point. Majic! :P