graph won't plot in correct spot
显示 更早的评论
% 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.
回答(1 个)
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()
类别
在 帮助中心 和 File Exchange 中查找有关 App Building 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
