How do I animate a point/particle move with certain velocity in a circular path?

11 visualizzazioni (ultimi 30 giorni)
I am able to make a point move with constant angular velocity along a circular path starting from a given initial position and radius of the circular path. Can I define the velocity of the moving point? Is it possible in Matlab?
crc = @(r,p,a) [r*cosd(a + p); r*sind(a + p)];
t = linspace(0, 360, 5); % Time
centre = [40; 80]; % Circle Centre
init_pos = atan2d(120-centre(2), 10-centre(1)); % Initial Position (°)
radius = hypot(10-centre(1), 120-centre(2)); % Circle Radius
locus = bsxfun(@plus, crc(radius, init_pos, t), centre); % Calculate Circle Locus
figure(1)
for k1 = 2:length(t)
plot(locus(1,k1), locus(2,k1), 'gp', 'MarkerFaceColor','g')
hold on
plot(locus(1,1:k1), locus(2,1:k1), '-b')
hold off
axis([0 60 0 160])
grid
axis equal
drawnow
end

Risposte (1)

Mischa Kim
Mischa Kim il 16 Set 2016
Modificato: Mischa Kim il 16 Set 2016
Vinaykanth, you just need to replace the angle a by something like om*t, where om represents the angular velocity.
crc = @(r,p,t,om) [r*cosd(om.*t + p); r*sind(om.*t + p)];
t = linspace(0, 360, 500); % Time
om = 1 + sin(t); % random angular velocity
centre = [40; 80]; % Circle Centre
init_pos = atan2d(120-centre(2), 10-centre(1)); % Initial Position (°)
radius = hypot(10-centre(1), 120-centre(2)); % Circle Radius
locus = bsxfun(@plus, crc(radius, init_pos, t, om), centre); % Calculate Circle Locus
figure(1)
for k1 = 2:length(t)
plot(locus(1,k1), locus(2,k1), 'gp', 'MarkerFaceColor','g')
hold on
plot(locus(1,1:k1), locus(2,1:k1), '-b')
hold off
axis([0 60 0 160])
grid
axis equal
drawnow
end
  2 Commenti
Vinaykanth Devu
Vinaykanth Devu il 16 Set 2016
Okay. But when we plot the circle with some random angular velocity, it is not a perfect circle but something like stars. When I put om=1 a circle is plotted, but if it is greater than 1 it is irregular in shape.
Mischa Kim
Mischa Kim il 16 Set 2016
Sure. The angular velocity I used was just an example. You need to use what is appropriate for you.
The irregular shape you are referring to results from the fact that all the data points are connected by straight lines. The moving point is still following a circular path.
You could either increase the number of data points in the linspace command to make the path indicated by the blue lines smoother, or simply remove the lines altogether.

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by