Circular motion of a big dog

1 view (last 30 days)
Sebastian
Sebastian on 5 Mar 2014
Commented: Image Analyst on 5 Mar 2014
High everybody.
I need to make a dog(a point) run around in a circle with a radius of 1 meter and angular velocity of 1 radian/sec. The time interval is 0-14*pi. The starting position of the dog is (1;0).
Hope somebody can help.
  1 Comment
Patrik Ek
Patrik Ek on 5 Mar 2014
You will need to clarify I guess. I am not really sure what you want to do here. Do you want the dots to be located at the right spot or do you want something that changes in time? If you want somehing that changes in time I guess that a movie could go well here, but if you want to do it with a plot it may be possible to get it to work anyway.
You will need to create a loop that is as short as possible, like the one you already have, to get a low runtime. Then run the function enough times to get a stable average runtime. After that, instead of using pause, which completely halts the matlab execution of the program, use a function that have a stable runtime and set this runtime to the value needed to give the dog the speed 1rad/sec. Functions like this may be found on the internet I guess.

Sign in to comment.

Answers (3)

Patrik Ek
Patrik Ek on 5 Mar 2014
Edited: Patrik Ek on 5 Mar 2014
Does it work with
r*[cos(0:14*pi)+1i*sin(0:14*pi)];
or do you need something else?
Other coordinates or structure should not be a problem. This will of course miss the end point so that one will have to be added in addition.

Image Analyst
Image Analyst on 5 Mar 2014
See the 4th example for circle in the FAQ http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F It's parameterized so basically theta is your time coordinate.

Sebastian
Sebastian on 5 Mar 2014
Edited: Sebastian on 5 Mar 2014
Thanks for the answers but I need a little more because i am trying to do it using functions.
This is how my code looks now:
function dog_running
t=linspace(0,14*pi,50);
x=cos(t);
y=sin(t);
markoer=plot(x(1),y(1),'r','MarkerSize',50);
axis equal
axis([-1.1,1.1,-1.1,1.1]);
for k=1:50
set(markoer,'XData',x(k),'YData',y(k))
pause(0.2)
end
function r=big_dog(t)
r=[cos(t);sin(t)];
The dot is moving as it should but I don't know how to implement the angular velocity and more important, how to do it with functions. The function I made doesn't do anything.
  2 Comments
Patrik Ek
Patrik Ek on 5 Mar 2014
This should not be an answer, please place it as an edit to the question. But no great harm done I guess:). Furthermore see my comment on top.
Image Analyst
Image Analyst on 5 Mar 2014
Why does it not do anything? Does it ever get called? If you set a breakpoint on the first line, does it stop there? Do you know how to debug?

Sign in to comment.

Categories

Find more on Loops and Conditional Statements 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!