graph won't plot in correct spot
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% 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 commentaires
Réponses (1)
Walter Roberson
le 19 Sep 2021
Modifié(e) : Walter Roberson
le 19 Sep 2021
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 commentaire
Walter Roberson
le 19 Sep 2021
Reminder: cos() and sin() expect radians . If you want to work with degrees, you need cosd() and sind()
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
