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

4 views (last 30 days)
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 Comments
Stephen23
Stephen23 on 24 Oct 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!

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 23 Oct 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

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!