how make 3d plotting

1 visualización (últimos 30 días)
Alpay Karadag
Alpay Karadag el 23 de Dic. de 2019
Respondida: Asvin Kumar el 26 de Dic. de 2019
function projmotion(x0,y0,v0,theta)
g = 9.8;
theta=45;
alpha=60;
v0=50;
y0=50;
x0=50;
z0=20;
angle = theta*(pi./180);
hangtime = 2*v0*sin(angle)/g;
t = hangtime;
x = v0*cos(theta)*sin(alpha)*t
y = v0*cos(theta)*sin(alpha)*t
z = z0+v0*sin(theta)*t-(g*t.^2)/2
if theta >90
maxheight = y0 + (v0)^2./(2*g)
xheight = x0 + v0*(t/2);
minheight = 0
error('Please select angle value of 90 degrees or less')
end;
figure('Color', [1 1 1]);
for k=0:t/100:t
x = x0 +(v0*k);
y = y0 +(v0*k)-0.5*g*(k^2);
z = z0 +(v0*k)
end
for k=0:t/100:t
x = x0 +(v0*k);
y = y0 +(v0*k)-0.5*g*(k^2);
z = z0 +(v0*k)
h = plot3(x,y,z,'.');
xlabel('Horizontal Distance (meters)');
ylabel('Height (meters)');
zlabel('Z');
title('Trajectory Time');
set(h,'MarkerSize',10);
set(h,'Color',[1,0.3,0.5]);
grid on
hold on;
pause(0.02);
end
this is my code but ı need circle on my code and the ball should fall to the ground how can I do it ?
  1 comentario
Adam Danz
Adam Danz el 23 de Dic. de 2019
Editada: Adam Danz el 23 de Dic. de 2019
"ı need circle on my code"
What does this mean? The trajectory should form a cirlce?
"...and the ball should fall to the ground"
??

Iniciar sesión para comentar.

Respuestas (1)

Asvin Kumar
Asvin Kumar el 26 de Dic. de 2019
Please have a look at the code below.
I assume when you say the ball should fall to the ground, it comes back to the same initial height. You can modify the time of flight to bring the vertical height to 0. I also assume that by “I need circle on my code” you mean you only want the instantaneous position of the ball to be displayed and not the trajectory. I’ve made more assumptions on what the variables mean. Feel free to modify them according to your equations.
function projmotion(x0,y0,v0,theta,alpha)
g = 9.8;
theta=45;
alpha=60;
v0=50;
y0=50;
x0=50;
z0=20;
if theta >90
error('Please select angle value of 90 degrees or less')
end
angle = theta*(pi./180);
angle2 = alpha*(pi./180);
t = 2*v0*sin(angle)/g;
figure('Color', [1 1 1]);
h = plot3(x0,y0,z0,'.','MarkerSize',10);
title('Trajectory');
set(h,'Color',[1,0.3,0.5]);
xlim(sort([x0 x0+v0*cos(angle)*cos(angle2)*t]))
ylim(sort([y0 y0+v0*cos(angle)*sin(angle2)*t]))
zlim(sort([z0 z0+v0.^2./(2*g)]))
grid on
hold on
xlabel('Horizontal Distance X (meters)');
ylabel('Horizontal Distance Y (meters)');
zlabel('Vertical Distance Z (meters)');
for k=0:t/100:t
x = x0 + v0*cos(angle)*cos(angle2)*k;
y = y0 + v0*cos(angle)*sin(angle2)*k;
z = z0 + v0*sin(angle)*k-(g*k.^2)/2;
cla % TOGGLE this command to plot trajectory vs the ball
plot3(x,y,z,'.','MarkerSize',10,'Color',[1,0.3,0.5]);
pause(0.02);
end
end

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by