【玩具】ANU Matlab Toy-Robot Movement Simulation
给朋友做的,当是放松了。。。本人真心不会matlab,下面的代码不代表个人水平,纯属堆砌。
这个程序模拟了一些机器人在一个方形空间中的移动轨迹。
clc; clear all; close all; %--------------------Input parameters------------------ %R=input( 'Number of Robots: ' ); %L=input( 'Length of the Room (m): ' ); %N=input( 'Number of Steps: ' ); %S=input( 'Maximum Size of each Step (cm):' ); %typeN=input( 'Type of the North Wall (Reflecting(0)/Absorbing(1)): ' ); %typeS=input( 'Type of the South Wall (Reflecting(0)/Absorbing(1)): ' ); %typeW=input( 'Type of the West Wall (Reflecting(0)/Absorbing(1)): ' ); %typeE=input( 'Type of the East Wall (Reflecting(0)/Absorbing(1)): ' ); %-----------random---------------- %R = round(unifrnd(3,10,1,1)); %L = round(unifrnd(1,10,1,1)); %N = round(unifrnd(10,100,1,1)); %S = round(unifrnd(10,100,1,1)); %---------pre_assignment------------------ R = 8; L = 1; N = 10; S = 50; typeN = 0; typeS = 0; typeW = 0; typeE = 0; %B=zeros(N+1,3); B=[]; B(1,:)=[0 0 0]; save result B; M=N; for i=1:R N = M; t = 1; position=[0 0 0]; while N>0 B(M-N+1,:)=position; save result B; step = rand(1,1)*S; d = floor(rand(1,1)*4); [nextposition,N] = newposition(d,step,position,L,typeN,typeS,typeW,typeE,N); position=nextposition; N=N-1; t=t+1; %disp(position); end B(t,:)=position; disp(B); plot3(B(:,1),B(:,2),B(:,3), '*-' , 'color' ,[mod(floor((i-1)/4),2),mod(floor((i-1)/2),2),mod((i-1),2)]); hold on ; title( 'Position of the Robots' ); text(0,0,0, 'Origin' ); text(0,50*L,0, 'North' ); text(0,-50*L,0, 'South' ); text(50*L,0,0, 'West' ); text(-50*L,0,0, 'East' ); axis([-50*L 50*L -50*L 50*L 0 M]); grid on end |
function [ nextposition ,N] = newposition( d,step,position,L,typeN,typeS,typeW,typeE,N ) %disp(position); if d==0 nextposition = position + [0 step 1]; if nextposition(2)>50*L if typeN==0 new=100*L-nextposition(2); nextposition(2)=new; else nextposition(2)=50*L; N=0; end end elseif d==1 nextposition = position + [0 -step 1]; if nextposition(2)<-50*L if typeS==0 new=-100*L-nextposition(2); nextposition(2)=new; else nextposition(2)=- 50*L; N=0; end end elseif d==2 nextposition = position + [step 0 1]; if nextposition(1)>50*L if typeE==0 new=100*L-nextposition(1); nextposition(1)=new; else nextposition(1)=50*L; N=0; end end else nextposition = position + [-step 0 1]; if nextposition(1)<-50*L if typeW==0 new=-100*L-nextposition(1); nextposition(1)=new; else nextposition(1)=-50*L; N=0; end end end end
关注分布式存储技术以及分布式计算方法
分类:
toy
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?