0

ランダムな回転行列を生成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.'たのですか?

4

1 に答える 1