I need help writing a program that makes the ball move along the path.

3 visualizaciones (últimos 30 días)
This is what my codes look likes:
clear all
clc
close all
createWindow(300,600);
obj = drawBall(0,300,5,'y');
x = 0:1:300;
y = 50 * sin(x/(10*pi)) + 100
plot(x,y)
for k = 1:x
xMove(obj,1)
yMove(obj,ystep)
redraw
end
Please help me figure out the ystep. I have no idea how to do it. Thanks in advance!
  3 comentarios
Stephen23
Stephen23 el 24 de Oct. de 2020
John Polo's orginal question retrieved from Google Cache:
I need help writing a program that makes the ball move along the path.
This is what my codes look likes:
clear all
clc
close all
createWindow(300,600);
obj = drawBall(0,300,5,'y');
x = 0:1:300;
y = 50 * sin(x/(10*pi)) + 100
plot(x,y)
for i = 1:x
xMove(obj,1)
yMove(obj,ystep)
redraw
end
Please help me figure out the ystep. I have no idea how to do it. Thanks in advance!

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Oct. de 2020
for k = 1:length(x)-1
xstep = x(k+1)-x(k);
xMove(obj, xstep)
ystep = y(k+1)-y(k);
yMove(obj, ystep)
redraw
end

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by