我正在尝试生成随机旋转矩阵R
,并将其应用于矢量。最后,我必须绘制原始矢量和旋转后的矢量。原始矢量必须用黑色虚线绘制,旋转后的矢量必须用黑色虚线绘制。我正确地完成了每个步骤,除了旋转点后无法绘制矢量。 MATLAB仅绘制矢量的起点和终点,但不完整。有趣的是,如果我尝试使用'k--'
而不是'k.'
,它可以正常工作。有人可以显示我在这里缺少什么吗?
% 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
%%%%% your code starts here %%%%%
% generate a random rotation matrix R
[R,N] = qr(randn(3));
% plot the x axis
plot3([0,1],[0,0],[0,0],'r');
text(1,0,0,'x')
% plot the y axis
plot3([0,0],[0,1],[0,0],'g');
text(0,1,0,'y')
% plot the z axis
plot3([0,0],[0,0],[0,1],'b');
text(0,0,1,'z')
% plot the original vector u
plot3([0,u(1)],[0,u(2)],[0,u(3)], 'k--');
text(u(1),u(2),u(3),['(',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.');
text(v(1),v(2),v(3),['(',num2str(v(1),'%.3f'),',',num2str(v(2),'%.3f'),',',num2str(v(3),'%.3f'),')'])
%%%%% your code ends here %%%%%
我用'k.'
取代了':k'
,它像一个吊饰一样工作。但是,我对发生的事情一无所知。为什么'k.'
不起作用?