How do I animate a point/particle move with certain velocity in a circular path?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Mischa Kim
am 16 Sep. 2016
Bearbeitet: Mischa Kim
am 16 Sep. 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 Kommentare
Mischa Kim
am 16 Sep. 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.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!