2016-05-17 70 views
0

我可以圍繞一個軸旋轉對象,但θ非常關閉 它應該以1度爲增量從1度旋轉到45度,但它的效果遠不止於此。我將θ(th)從度數轉換爲弧度,但問題仍然存在。3d對象上的旋轉增量關閉

下面就來旋轉 animation of the rotation https://www.dropbox.com/s/bnc7m4fxipicizr/rot2.gif

的動畫鏈接的代碼如下:我使用的是八度4.0這就好比MATLAB

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

這是因爲你在每次迭代更新'X','Y'和'Z'而加倍th'的'值。嘗試運行代碼而不更改循環中'theta'的值 – BillBokeey

+0

@BillBokeey如果我不更改'th'(θ)我將如何得到任何旋轉? –

+3

每次迭代你都會得到1°的旋轉角度,這就是你想要的(當然你必須在for循環之前定義'th = pi/180')。 (試試吧) – BillBokeey

回答

0

決定發佈解決方案,以防有人遇到類似問題。感謝所有去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