我可以围绕一个轴旋转一个物体但是θ非常关闭 它应该以1度的增量从1度旋转到45度,但它的功能远不止于此。我将theta(th)从度数转换为弧度,但问题仍然存在。
这是旋转动画的链接 https://www.dropbox.com/s/bnc7m4fxipicizr/rot2.gif
代码如下:
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我正在使用octave 4.0,就像matlab一样。
答案 0 :(得分: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