finding the distance between points
5 ビュー (過去 30 日間)
古いコメントを表示
Hi! I'm studying for finals and I'm trying to rework a test problem. It's stumped me and I could use the help!
This is the problem:
Consider two airplanes that launch at the same moment and fly in the first quad of a 2-D space. Airplane A always travels at 800 km/h along a direction that makes a 20 degree angle with the x axis and originates at the coordinate origin. Airplane B always travels at 950 km/h in a direction that makes a 70 degree angle with the x axis and originates at 1000km in the x direction and 2000 km in the y direction. Make a function file that returns the distance between the two planes at a given time. Test your function at t=0,1, and 2 hrs.
I think I need to use either the norm function or the sqrt (x^2 + y^2) to find the distance but I'm kind of confused how to bring in the speed and what not into the equation. PLEASE HELP!
1 件のコメント
Matt Kindig
2013 年 4 月 30 日
編集済み: Matt Kindig
2013 年 4 月 30 日
Write down (on paper) the equations for X and Y for each plane first. Hint:
X(t) = X0 + Vx*t %x position at time t, velocity-x component
You should then be able to figure out how to calculate the distance from there. The sqrt(x^2+y^2) thing you had will help.
採用された回答
Youssef Khmou
2013 年 4 月 30 日
編集済み: Youssef Khmou
2013 年 4 月 30 日
hi,
the Dynamic 2D position is defined as :
X(t)=V*cos(theta)*t+X0 & Y(t)=V*sin(theta)*t+Y0 .
Try this version :
theta_a=20*pi/180;
theta_b=70*pi/180;
Va=800; % Km/h
Vb=950; % Km/h
x0a=0;
y0a=0;
x0b=1000;
y0b=2000;
% Time simulation
T=0:0.5:10; % 10 hours, we measure the distance every 30 minutes
% first airplane
Xa=Va*cos(theta_a)*T+x0a;
Ya=Va*sin(theta_a)*T+y0a;
Xb=Vb*cos(theta_b)*T+x0b;
Yb=Vb*sin(theta_b)*T+y0b;
for t=1:length(T)
D(t)=sqrt((Xa(t)-Xb(t)).^2+(Ya(t)-Yb(t)).^2);
end
figure, plot(T,D), xlabel(' Time in Hours'), ylabel(' Distance /KM')
title(' Distance between two airplanes a and b '), grid on
Try now to make it as function
1 件のコメント
Youssef Khmou
2013 年 4 月 30 日
so the function take t as input
Y=Yourfunction(t)
% Constantes
compute X(t) and Y(t)
compute the distance D(X(t),Y(t))
......
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!