MATLAB Answers

Rotating projectile curve about y-axis

조회 수: 5(최근 30일)
Rahul Venkatraman
Rahul Venkatraman 6 Apr 2020
댓글: darova 7 Apr 2020
I am trying to create a surface by revolving my x,y plot about the y axis. Basically, it should look like the upper half of a torus. The cuve itself plots the projectile motion of an object.
First code is mine:
close all
clc
x0 = 0;
y0 = 0; % Assume initial height is after impact with surface
t = 0:0.1:10;
g = 9.81;
theta = 45; % Maximum theoretical range in little to no drag
v0 = 10;
x = x0 + v0*cos(theta*(pi()/180))*t;
y = y0 + v0*sin(theta*(pi()/180))*t - 0.5 * g * t.^2
plot(x,y)
ylim([0 inf])
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Second is taken from an author:
close all
clc
% Projectile motion simulation
x0=0; % m
y0=0; % m
v0=10; % m/s
theta=45; % deg
g=9.81; % m/s^2
t_flight=calc_t_flight(g,v0,theta,y0)
range=calc_range(v0,theta,t_flight)
v_impact=calc_v_impact(g,v0,theta,t_flight,y0)
t=linspace(0,t_flight,30);
xdot0=v0*cos(pi*(theta/180));
ydot0=v0*sin(pi*(theta/180));
x=xdot0*t+x0;
y=-(g/2)*t.^2+ydot0*t+y0;
plot(x,y)
axis([0 inf 0 inf])
xlabel(sprintf('Distance (m) - Range = %5.3f',range));
ylabel('Height (m)');
title(sprintf('Projectile motion: v_{impact} = %5.3f m/s',v_impact));
% [X,Y,Z]=cylinder(y);
% surf(Y,Z,X)
% axis ([-10 10 0 10 -10 10])
% xlabel('X');ylabel('Z');zlabel('Y','Rotation',0)

  댓글 수: 0

로그인 to comment.

답변(1개)

darova
darova 6 Apr 2020
You can create a mesh in polar system of coordinates
Assuming
t = linspace(0,2*pi,30); % angle
r = x; % you radius
z = y; % z axis
Z is not chainging in polar system
Use meshgrid to create a mesh
[T,R] = meshgrid(t,r);
[~,Z] = meshgrid(t,z);
Use pol2cart to convert polar coordinate into cartesian

  댓글 수: 2

Rahul Venkatraman
Rahul Venkatraman 7 Apr 2020
This is my updated code. I tried your suggestion but it did not work.
clear all
close all
clc
% INITIAL DROP HEIGHT [M]
g = 9.81;
y01 = 1;
x0 = 0;
yf = 0;
t = sqrt(2*(yf-y01)/(-1*g))
vy0 = g * t
y02 = 0;
%%
alpha1 = 0;
ttraj1 = 2*vy0*cos((alpha1)*(pi/180))/g;
tf1 = ttraj1;
tspan1 = [0.01:0.01:tf1];
for i = 1:length(tspan1)
x1(i) = x0 + vy0*sin((alpha1)*(pi/180))*tspan1(i);
end
xmax1 = max(x1);
for i = 1:length(tspan1)
y1(i) = y02 + vy0*cos((alpha1)*(pi/180))*tspan1(i) - 0.5*g*(tspan1(i))^2;
end
%%
alpha2 = 15;
ttraj2 = 2*vy0*cos((alpha2)*(pi/180))/g;
tf2 = ttraj2;
tspan2 = [0.01:0.01:tf2];
for i = 1:length(tspan2)
x2(i) = x0 + vy0*sin((alpha2)*(pi/180))*tspan2(i);
end
xmax2 = max(x2);
for i = 1:length(tspan2)
y2(i) = y02 + vy0*cos((alpha2)*(pi/180))*tspan2(i) - 0.5*g*(tspan2(i))^2;
end
%%
alpha3 = 30;
ttraj3 = 2*vy0*cos((alpha3)*(pi/180))/g;
tf3 = ttraj3;
tspan3 = [0.01:0.01:tf3];
for i = 1:length(tspan3)
x3(i) = x0 + vy0*sin((alpha3)*(pi/180))*tspan3(i);
end
xmax3 = max(x3);
for i = 1:length(tspan3)
y3(i) = y02 + vy0*cos((alpha3)*(pi/180))*tspan3(i) - 0.5*g*(tspan3(i))^2;
end
%%
alpha4 = 45;
ttraj4 = 2*vy0*cos((alpha4)*(pi/180))/g;
tf4 = ttraj4;
tspan4 = [0.01:0.01:tf4];
for i = 1:length(tspan4)
x4(i) = x0 + vy0*sin((alpha4)*(pi/180))*tspan4(i);
end
xmax4 = max(x4);
for i = 1:length(tspan4)
y4(i) = y02 + vy0*cos((alpha4)*(pi/180))*tspan4(i) - 0.5*g*(tspan4(i))^2;
end
%%
alpha5 = 60;
ttraj5 = 2*vy0*cos((alpha5)*(pi/180))/g;
tf5 = ttraj5;
tspan5 = [0.01:0.01:tf5];
for i = 1:length(tspan5)
x5(i) = x0 + vy0*sin((alpha5)*(pi/180))*tspan5(i);
end
xmax5 = max(x5);
for i = 1:length(tspan5)
y5(i) = y02 + vy0*cos((alpha5)*(pi/180))*tspan5(i) - 0.5*g*(tspan5(i))^2;
end
%%
figure(1)
plot(tspan1,x1,'linewidth',2)
hold on
plot(tspan2,x2,'linewidth',2)
plot(tspan3,x3,'linewidth',2)
plot(tspan4,x4,'linewidth',2)
plot(tspan5,x5,'linewidth',2)
xlabel('t')
ylabel('x')
legend('\alpha = 0','\alpha = 15','\alpha = 30','\alpha = 45','\alpha = 60')
figure(2)
plot(tspan1,y1,'linewidth',2)
hold on
plot(tspan2,y2,'linewidth',2)
plot(tspan3,y3,'linewidth',2)
plot(tspan4,y4,'linewidth',2)
plot(tspan5,y5,'linewidth',2)
xlabel('t')
ylabel('y')
legend('\alpha = 0','\alpha = 15','\alpha = 30','\alpha = 45','\alpha = 60')
figure(3)
plot(x1,y1,'linewidth',2)
hold on
plot(x2,y2,'linewidth',2)
plot(x3,y3,'linewidth',2)
plot(x4,y4,'linewidth',2)
plot(x5,y5,'linewidth',2)
xlabel('x')
ylabel('y')
legend('\alpha = 0','\alpha = 15','\alpha = 30','\alpha = 45','\alpha = 60')
% y = 0;
% line([0,xmax3],[y,y],'linewidth',2)
% legend('radius')
% hold off
darova
darova 7 Apr 2020
Maybe you understood me in a wrong way
clc
x0 = 0;
y0 = 0; % Assume initial height is after impact with surface
t = 0:0.1:2;
g = 9.81;
theta = 45; % Maximum theoretical range in little to no drag
v0 = 10;
x = x0 + v0*cos(theta*(pi()/180))*t;
y = y0 + v0*sin(theta*(pi()/180))*t - 0.5 * g * t.^2;
t = linspace(0,2*pi,30); % angle
r = x; % you radius
z = y; % z axis
[T,R] = meshgrid(t,r);
[~,Z] = meshgrid(t,z);
[X,Y] = pol2cart(T,R);
surf(Y,Z,X,'facecolor','none')
line(x,y,'linewidth',3)
axis equal vis3d

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by