graph won't plot in correct spot
1 回表示 (過去 30 日間)
古いコメントを表示
% plot mountain
Mn_x = [0, 1000, 3014.8];
Mn_y = [0, 6, 1000];
plot (Mn_x, Mn_y)
hold on
% known variables
Xo = 0;
Yo = 1;
V = 585; % m/s
G = 9.81; % m/s^2
t = linspace(0, 8, 800);
th1 = 10; % degrees
th2 = 12; % degrees
th3 = 14; % degrees
% calculate trajectory of howitzer
x_th1 = Xo + (V * cos(th1)) * t
y_th1 = Yo + (V * sin(th1)) * t - 1/2 * G * (t.^2)
plot (x_th1, y_th1, 'r')
Plot (x_th1, y_th1) is supposed to start at (0,1) but actually starts at (-3900,-2800) I've tried fixing the equations but I can't figure out whats wrong.
0 件のコメント
回答 (1 件)
Walter Roberson
2021 年 9 月 19 日
編集済み: Walter Roberson
2021 年 9 月 19 日
If you do not want negative values shown, then clip them out of the plot by adjusting xlim and ylim.
% plot mountain
Mn_x = [0, 1000, 3014.8];
Mn_y = [0, 6, 1000];
plot (Mn_x, Mn_y)
hold on
% known variables
Xo = 0;
Yo = 1;
V = 585; % m/s
G = 9.81; % m/s^2
t = linspace(0, 8, 800);
th1 = 10; % degrees
th2 = 12; % degrees
th3 = 14; % degrees
% calculate trajectory of howitzer
x_th1 = Xo + (V * cos(th1)) * t
y_th1 = Yo + (V * sin(th1)) * t - 1/2 * G * (t.^2)
plot (x_th1, y_th1, 'r')
XL = xlim();
YL = ylim();
xlim( [max(0, XL(1)), XL(2)]);
ylim( [max(1, YL(1)), YL(2)]);
1 件のコメント
Walter Roberson
2021 年 9 月 19 日
Reminder: cos() and sin() expect radians . If you want to work with degrees, you need cosd() and sind()
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!