matlab圆台动画

demo1.m

u=0:0.01:0.5;
x0=2-u.*sin(pi/6);
y0=zeros(size(u));
z0=u.*cos(pi/6);
P0=[x0;y0;z0];
plot3(P0(1,:),P0(2,:),P0(3,:),'b');
xlabel('x');
ylabel('y');
zlabel('z');
hold on;
omega=repmat([0;0;1],size(x0,1),size(x0,2));
theta=0:pi/180:2*pi;
for i=1:length(theta)
	P=RotateAxisTheta(omega,P0,theta(i));
	plot3(P(1,:),P(2,:),P(3,:),'b');
	drawnow
	f = getframe(gcf);
	imind = frame2im(f);
	[imind,cm] = rgb2ind(imind,256);
	if i == 1
		imwrite(imind,cm,'demo.gif','gif', 'Loopcount',inf,'DelayTime',0.1);
	else
		imwrite(imind,cm,'demo.gif','gif','WriteMode','append','DelayTime',0.1);
	end
end

RotateAxisTheta.m

function Rn = RotateAxisTheta(omega,R,theta)
%Input:
%   omega:旋转轴的矢量三维坐标 可以是3×1 vector,也可以是3×n的矩阵,每一列都是一个vector
%   R:旋转前的矢量 可以是3×1 vector,也可以是3×n的矩阵,每一列都是一个vector(列数和omega相等)
%   theta:旋转的角度,单位是rad
%Output:
%   Rn:旋转后的矢量
%Rn=ones(3,1);
Rn=cos(theta)*R+sin(theta)*cross(omega,R)+(1-cos(theta))*dot(omega,R).*omega;
end

在这里插入图片描述
随便玩玩~后面有时间讲讲旋转函数RotateAxisTheta.m的具体原理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值