Calculating a rotation quaternion from two vectors then applying the rotation to a point

686 Views Asked by At

I'm new to quaternions and I'm trying to construct a method of find the rigid body motion of an object based on an origin plane (say xy) and its displaced plane (say x'y') so that I can repeat the rotation to some other points on the object.

I'm calculating this in excel, and my current calculations seem to work for a rotation of 90deg around the x axis or 90deg around the y axis, but for nothing else... Ultimately, I want a solution that can repeat a rotation based on the displaced plane without having to know the pitch, roll and yaw or sequence in which to apply them. If you have time, please could you take a look over my approach and see if I've made any obvious mistakes.

I've uploaded the excel sheet that I'm playing around with.

I'll try to explain my working below:

Starting with the 4 points on the original plane and the deformed plane, I find the centroid (in my excel sheet the centroid is 0, but when I use this solution I will need to stay in a global axis and so the centroids will be at positions x,y,z).

Next I find two vectors on each plane from the centroids to two of the points, call these $a_{1,2}$ and $b_{1,2}$. I then find the cross product between the two $a$ vectors and the two $b$ vectors, i.e. $c_{1}$ and $c_{2}$.

I then normalise these vectors to give me $N_{1}$ and $N_{2}$.

Next I create a vector (and normalise again after), $M = N_{1} + N_{2}$

Now I find the terms for my rotation quaternion using the dot product for the angle and the cross product for the axis:

$q(w) = M \cdot N_{2}$ and $q(v) = M \times N_{2}$

I then find $q'$ and do the following calculations in order to try and rotate one of the points on the original plane to the displaced plane (in order to check my answer).

This seems to work for cases where I've rotated about the X or the Y axis by 90 degrees, but it doesn't work for 45 degrees or where I've used multiple rotations.

Thanks in advanced for any help