clc; clear;

Vm = 750; % maximum velocity Vt = 600; % target velocity r0 = 1000; % initial distance to target q0 = 90; % initial angle x = 0; % initial x-coordinate y = 0; % initial y-coordinate X = 0; % final x-coordinate Y = 1000; % final y-coordinate x1= 0; % relative x-coordinate time = 0; % initial time interval = 0.01; % time interval D = [time;q0]; % initial angle and time DD = [D' x y 0 1000 0]; % matrix to store data

while(x<=X)

D = [time;atand((Y-y)/(X-x))]; % calculate angle based on current position

x = x + Vm*cosd(D(2))*interval; % update x-coordinate
y = y + Vm*sind(D(2))*interval; % update y-coordinate
X = X + 600*interval; % update final x-coordinate

x1 = x1 + (Vm*cosd(D(2))-600)*interval; % update relative x-coordinate

DD = [DD;D' x y X Y x1]; % store data in matrix
time = time + interval; % update time

end

% Plotting the trajectory figure(1); plot(DD(:,3),DD(:,4),'LineWidth',1.5);hold on; % plot x versus y plot(DD(:,5),DD(:,6),'r','LineWidth',1.5); % plot X versus Y

% Plotting the relative x-coordinate figure(2); plot(DD(:,7),DD(:,4),'LineWidth',1.5);hold on; % plot x1 versus

clc;clear;Vm = 750;Vt = 600;r0 = 1000;q0 = 90;x = 0;y = 0X = 0;Y = 1000;x1= 0;time = 0;interval = 001;D = time;q0;DD = D x y 0 1000 0;whilex=X D = time;atandY-yX-x; x = x + VmcosdD2interval;

原文地址: https://www.cveoy.top/t/topic/hWkG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录