四元数定义

单位四元数



这一性质十分有用。
由于多次的旋转矩阵间相乘会导致误差累积,相乘次数越多误差越大。
如果利用单位四元数表示旋转矩阵,相乘后得到另一个单位四元数,这时对这个四元数进行renormalize就可以提高精度。

共轭

先进性

这一表示形式在机器人学,计算机视觉有着广泛应用。

旋转表示方式的总结

rigid-transformation


inverting rigid transformation

SpecialEulerianGroup


exercise




code

function q=quatprod(q1,q2)
    % All quaternions q, q1 and q2 are represented as 1-by-4 row vectors 
    q=zeros(1,4);
    u0 = q1(1);
    u = q1(2:end);
    v0 = q2(1);
    v = q2(2:end);


    q(1)= u0 * v0 - u * v';
    temp = u0 * v + v0 * u + cross(u, v);
    q(2)=temp(1);
    q(3)=temp(2);
    q(4)=temp(3);


end

visualized rotation

% rand(3,1) generates a random 3 by one column vector. We use this u to plot
u=rand(3,1)*2-1;

% plot the origin
plot3(0,0,0,'.k')

% axis setting
axis vis3d
axis off


% generate a random rotation matrix R
theta = 2*pi*rand();
w = rand(1,3);
w = w / norm(w);

k0 = cos(theta/2);
k = sin(theta/2) * w;

R = (k0^2 - (k*k'))*eye(3) + 2*k0*[0,-k(3),k(2);k(3),0,-k(1);-k(2), k(1),0] + 2 * (k' * k);

% plot the x axis 
plot3([0,1],[0,0],[0,0],'r');
text(1,0,0,'x');
hold on;
% plot the y axis 
plot3([0,0],[1,0],[0,0],'g');
text(0,1,0,'y');
hold on;
% plot the z axis 
plot3([0,0],[0,0],[1,0],'b');
text(0,0,1,'z');
hold on;
% plot the original vector u
plot3([0,u(1)],[0,u(2)],[0,u(3)],'k--'); % black-dashed-line
text(u(1),u(2),u(3),['u','(',num2str(u(1),'%.3f'),',',num2str(u(2),'%.3f'),',',num2str(u(3),'%.3f'),')']);
hold on;
% apply rotation and calcuate v plot the vector after rotation v
v = R * u;

% plot the new vector v
plot3([0,v(1)],[0,v(2)],[0,v(3)],'k:'); % black-dotted-line
text(v(1),v(2),v(3),['v','(',num2str(v(1),'%.3f'),',',num2str(v(2),'%.3f'),',',num2str(v(3),'%.3f'),')']);
hold on;