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개)
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()
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
