# Quaternion for beginner

QUATERNION ROTATIONI have 2 points in 3d space ,point A= <5,3,6> and B=<8,2,3>

I want to rotate "point B" by 30 degree from point A.

how do I solve this question using quaternion.

Plz, explain the steps....

• To specify a rotation you need to give the axis (in addition to the angle). What is the axis here? In other words, what does the phrase 30 degree from point A mean? – Jyrki Lahtonen Apr 8 '16 at 4:02

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:

# 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

• Note that you will need to do a pretty large expansion to get $p_\text{new}$ – user2662833 Apr 8 '16 at 4:51

if i want to want to rotate vector [3,5,-2] 90 degrees about X axis. Our angle x is 90 and axis v is [1,0,0] (X axis).

The quaternion q is: q = cos(45) + [1,0,0]*sin(45) = 0.707 + 0.707*i It turns out, that: 1/q = 0.707 - 0.707*i

Vector w, as a quaternion, is 3i + 5j - 2k. Now we have to calculate: (0.707+0.707*i)(3i+5j-2k)(0.707-0.707*i) = (after many calculations) = 3i + 2j + 5k So, the rotated vector is [3,2,5].