I use the following scheme:
Quaternion: [ w, x, y, z ]
Then I use Euler Angles and convert it to a quaternion, as following:
bank = 180; // x axis
heading = 80; // y axix
attitude = 20; // z axix
DegreeToRadian = 3.14/180;
c1 = cos(heading/2*DegreeToRadian);
c2 = cos(attitude/2*DegreeToRadian);
c3 = cos(bank/2*DegreeToRadian);
s1 = sin(heading/2*DegreeToRadian);
s2 = sin(attitude/2*DegreeToRadian);
s3 = sin(bank/2*DegreeToRadian);
q.w = c1*c2*c3 - s1*s2*s3;
q.x = s1*s2*c3 + c1*c2*s3;
q.y = s1*c2*c3 + c1*s2*s3;
q.z = c1*s2*c3 - s1*c2*s3;
And then I normalize:
n = sqrt(q.w*q.w+q.x*q.x+q.y*q.y+q.z*q.z)
q = {w/n, x/n, y/n, z/n}
$w+x+y+z$ should equal $1$, but it is wrong! And when I convert the quaternion to a matrix, I have a big distortion.
I created this in Excel, you can see it online. OneDrive Excel Google Sheets
Please, Help me.
You normalized with respect to the sum of the squares; why would you expect that the sum of the components would equal 1 then? Looking at your google doc, the sum of the squares is 1, the way it should be.
Why is this the case? Consider a very simple quaternion, representing a rotation about $\hat x$ by an angle $\theta$.
$$q = \cos \frac{\theta}{2} + i \sin \frac{\theta}{2}$$
It's not true that $\cos \frac{\theta}{2} + \sin \frac{\theta}{2} = 1$, but it is true that $q q^* = \cos^2 \frac{\theta}{2} + \sin^2 \frac{\theta}{2} = 1$.