2016-05-17 14 views
0

軸を中心にオブジェクトを回転させることはできますが、シータは非常にオフです 1度から45度まで1度ずつ回転させる必要がありますが、私はtheta(th)を度からラジアンに変換しましたが、それでも問題は発生します。3dオブジェクトの回転増分がオフです

は、ここで回転 animation of the rotation https://www.dropbox.com/s/bnc7m4fxipicizr/rot2.gif

のアニメーションへのリンクだとコードは以下の通りです:私はMathWorks社のMATLABのようなものですオクターブ4.0を使用してい

clf 
[Z,Y,X] = cylinder(10:-1:0, 50); 
xlabel('X axis') 
ylabel('Y axis') 
zlabel('Z axis') 
array_sz_begin=size(X); 
W=repmat(1,array_sz_begin); %create ones for w 
figure(1), clf;surf(X,Y,Z);axis equal; 
%--- z-rotation matrix Rz 
for n=1:1:45 
    th=n*pi/180; %angle of rotation converted to radians; 
    Rz=[cos(th) -sin(th) 0 0;sin(th) cos(th) 0 0;0 0 1 0;0 0 0 1]; 
    P=[X(:) Y(:) Z(:) W(:)]*Rz; %rotate each point on surface 
    X=reshape(P(:,1),array_sz_begin);%transform surface vertices back 
    Y=reshape(P(:,2),array_sz_begin); 
    Z=reshape(P(:,3),array_sz_begin); 
    xlabel('X axis') 
    ylabel('Y axis') 
    zlabel('Z axis') 
    clear P; 
    title(['Shift in ',num2str(n),' deg']); 
    hold on;surf(X,Y,Z);axis equal; 
    pause (.5) 
end 

PS。

+2

に行きます。ループ内の 'theta 'の値を変更せずにコードを実行してみてください – BillBokeey

+0

' th'(theta)を変更しないと@BillBokeeyどのように回転しますか? –

+3

あなたは1回の回転ごとに1度の回転を得ます。これはあなたが望むものです(forループの前に 'th = pi/180'を定義する必要があります)。 (ただ試してみてください) – BillBokeey

答えて

0

誰かがこのような問題を抱えている場合に備えて、ソリューションを投稿することに決めました。すべてのおかげでth` `の値を倍にしながら、あなたは 'X'、` Y`と `Z`は、各反復で更新するためですBillBokeey

clf 
[Z_orig,Y_orig,X_orig] = cylinder(10:-1:0, 50); 
xlabel('X axis') 
ylabel('Y axis') 
zlabel('Z axis') 
array_sz_begin=size(X_orig); 
W=repmat(1,array_sz_begin); %create ones for w 
figure(1), clf;surf(X_orig,Y_orig,Z_orig);axis equal; 
%--- define z-rotation matrix Rz 

for n=1:1:90 

    th=n*pi/180; %angle of rotation converted to radians; 
    Rz=[cos(th) -sin(th) 0 0;sin(th) cos(th) 0 0;0 0 1 0;0 0 0 1]; 
    %Rz=[cos(th) -sin(th) 0;sin(th) cos(th) 0;0 0 1]; 
    P=[X_orig(:) Y_orig(:) Z_orig(:) W(:)]*Rz; %rotate each original point on surface 
    X=reshape(P(:,1),array_sz_begin);%transform surface vertices's back 
    Y=reshape(P(:,2),array_sz_begin); 
    Z=reshape(P(:,3),array_sz_begin); 
    xlabel('X axis') 
    ylabel('Y axis') 
    zlabel('Z axis') 
    clear P; 
    title(['Rotate in ',num2str(n),' deg']); 
    hold on;surf(X,Y,Z);axis equal; 
    pause (.1) 
    clear P 
end 
関連する問題