function draw_the_animated_picture_2()
% 输入 引力系数k, 时间步长 N, 时间尺度 T,
% 以及多个物体的质量和初始位置和速度,画出
% 三维运动gif图像。
%输入k,N,T.
clear all;
close all;
clc;
k = 1;
N = 10;
T = 2;
%输入质量
% m1 = 10;
% m2 = 1;
% m3 = 2;
% m4 = 3;
% M = [m1,m2,m3,m4];
M = rand(1,N);
M(1) = 100000;
%输入初始位置。
% x1 = 1-2*rand(1);
% x2 = 1-2*rand(1);
% x3 = 1-2*rand(1);
% x4 = 1-2*rand(1);
% y1 = 0;
% y2 = 0;
% y3 = 0;
% y4 = 0;
% z1 = 0;
% z2 = 0;
% z3 = 0;
% z4 = 0;
% XX = [x1,x2,x3,x4];
% YY = [y1,y2,y3,y4];
% ZZ = [z1, z2,z3,z4];
XX = (2.*rand(1,N) - ones(1,N)).*10;
YY = (2.*rand(1,N) - ones(1,N)).*10;
ZZ = (2.*rand(1,N) - ones(1,N)).*10;
%输入初始速度。
% xd1 = 0;
% xd2 = 0;
% xd3 = 0;
% xd4 = 0;
% yd1 = 1*(1-2*rand(1));
% yd2 = 100*(1-2*rand(1));
% yd3 = 100*(1-2*rand(1));
% yd4 = 100*(1-2*rand(1));
% zd1 = 1;
% zd2 = 10;
% zd3 = -10;
% zd4 = 5;
% XXd = [xd1,xd2,xd3,xd4];
% YYd = [yd1,yd2,yd3,yd4];
% ZZd = [zd1,zd2,zd3,zd4];
XXd = 100.*rand(1,N) - 50.*ones(1,N);
YYd = 100.*rand(1,N) - 50.*ones(1,N);
ZZd = 100.*rand(1,N) - 50.*ones(1,N);
XXd(1) = XXd(1)./30;
YYd(1) = YYd(1)./30;
ZZd(1) = ZZd(1)./30;
% XXd(N) = XXd(N)./100;
% YYd(N) = YYd(N)./100;
% ZZd(N) = ZZd(N)./100;
N1 = 4000;
XYZ = zeros(N,3,N1);
XYZd = zeros(N,3);
XYZ(:,1,1) = XX;
XYZ(:,2,1) = YY;
XYZ(:,3,1) = ZZ;
XYZd(:,1) = XXd;
XYZd(:,2) = YYd;
XYZd(:,3) = ZZd;
XYZ = output_the_location_data...
(k,N,T,N1,M,XYZ,XYZd);
%初始化多个物体位置矩阵XYZ。
% dd1 = 10;
% for N1 = 2000 :2000 :10000
% % N1 = 1000;
% XYZ = zeros(N,3,N1);
% XYZd = zeros(N,3);
%
% XYZ(:,1,1) = XX;
% XYZ(:,2,1) = YY;
% XYZ(:,3,1) = ZZ;
% XYZd(:,1) = XXd;
% XYZd(:,2) = YYd;
% XYZd(:,3) = ZZd;
%
% XYZ = output_the_location_data...
% (k,N,T,N1,M,XYZ,XYZd);
% dd0 = max(max(max(abs(XYZ))));
% dd1 = dd0 - dd1;
% dd2 = dd1/dd0;
% if dd2 < 10^-3
% break;
% else
% ;
% end
% end
% xx1(1,:) = XYZ(1,1,:);
% xx2(1,:) = XYZ(2,1,:);
% xx3(1,:) = XYZ(3,1,:);
% xx4(1,:) = XYZ(4,1,:);
% yy1(1,:) = XYZ(1,2,:);
% yy2(1,:) = XYZ(2,2,:);
% yy3(1,:) = XYZ(3,2,:);
% yy4(1,:) = XYZ(4,2,:);
% zz1(1,:) = XYZ(1,3,:);
% zz2(1,:) = XYZ(2,3,:);
% zz3(1,:) = XYZ(3,3,:);
% zz4(1,:) = XYZ(4,3,:);
xx = zeros(N,N1);
yy = zeros(N,N1);
zz = zeros(N,N1);
for i1 = 1 : N
xx(i1,:) = XYZ(i1,1,:);
yy(i1,:) = XYZ(i1,2,:);
zz(i1,:) = XYZ(i1,3,:);
end
%确定作图时的坐标范围。
% Xmax = max([xx1,xx2,xx3,xx4]);
% Ymax = max([yy1,yy2,yy3,yy4]);
% Zmax = max([zz1,zz2,zz3,zz4]);
% Xmin = min([xx1,xx2,xx3,xx4]);
% Ymin = min([yy1,yy2,yy3,yy4]);
% Zmin = min([zz1,zz2,zz3,zz4]);
% Xmax = max(max(xx));
% Ymax = max(max(yy));
% Zmax = max(max(zz));
% Xmin = min(min(xx));
% Ymin = min(min(yy));
% Zmin = min(min(zz));
%
% Xlim=[Xmin,Xmax]./10./N;
% Ylim=[Ymin,Ymax]./10./N;
% Zlim=[Zmin,Zmax]./10./N;
% Xlim = [XX(1)*-10,XX(1)*10];
% Ylim = [YY(1)*-10,YY(1)*10];
% Zlim = [ZZ(1)*-10,ZZ(1)*10];
% TT = T/N1 : T/N1 : T;
%作出三维运动图像,保存成gif。
for i1 = 1 : 50 : N1
% X = [xx1(i1),xx2(i1),xx3(i1),xx4(i1)];
% Y = [yy1(i1),yy2(i1),yy3(i1),yy4(i1)];
% Z = [zz1(i1),zz2(i1),zz3(i1),zz4(i1)];
X = xx(:,i1);
Y = yy(:,i1);
Z = zz(:,i1);
% subplot(211);
scatter3(X,Y,Z,'filled');
xlim([abs(XX(1))*-10,abs(XX(1))*10]);
ylim([abs(YY(1))*-10,abs(YY(1))*10]);
zlim([abs(ZZ(1))*-10,abs(ZZ(1))*10]);
title(['N=',num2str(N)]);
% subplot(212);
% xlim([0 T]);
% ylim(Xlim);
% scatter(TT(i1),xx1(i1),'filled','r');hold on;
% scatter(TT(i1),xx2(i1),'filled','b');hold on;
% scatter(TT(i1),xx3(i1),'filled','y');hold on;
% scatter(TT(i1),xx4(i1),'filled','g');
% scatter3(X1(i1),Y1(i1),Z1(i1),'r','filled');hold on;
% scatter3(X2(i1),Y2(i1),Z2(i1),'b','filled');hold on;
% scatter3(X3(i1),Y3(i1),Z3(i1),'y','filled');hold on;
grid on;
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
outfile = 'santi10.gif';
% On the first loop, create the file. In subsequent loops, append.
if i1==1
imwrite(imind,cm,outfile,'gif','DelayTime',0,'loopcount',inf);
else
imwrite(imind,cm,outfile,'gif','DelayTime',0,'writemode','append');
end
end
end
weixin_42651887
- 粉丝: 97
- 资源: 1万+
最新资源
- 同济大学作业之-LPC分析(男声变女声)和PCM编码
- java超市订单管理系统源码数据库 MySQL源码类型 WebForm
- 记录windows安装nvm:nvm-setup-2024-11-16.exe.zip
- 同济大学数字信号处理实验(包含实验报告)
- Kettle 是Kettle E.T.T.L. Envirnonment只取首字母的缩写,这意味着它被设计用来帮助你实现你的
- java微信小程序B2C商城 H5+APP源码 前后端分离数据库 MySQL源码类型 WebForm
- matplotlib 绘制随机漫步图
- java版快速开发框架后台管理系统源码数据库 MySQL源码类型 WebForm
- Java实现植物大战僵尸简易版
- matplotlib 绘制随机漫步图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈