Moving a dot at a constant velocity in a circular path in MATLAB

24 ビュー (過去 30 日間)
VINAY KUMAR REDDY MEDAPATI
VINAY KUMAR REDDY MEDAPATI 2016 年 9 月 13 日
編集済み: Maryam Naveed 2019 年 4 月 24 日
Hello, I want to present a dot in a rectangular field and make it move in the field at a constant velocity in a circular path (the position of the dot has to be known with respect to time). Additionally I want to manipulate the initial position in which it will be presented. Can anyone help me ?
  2 件のコメント
James Tursa
James Tursa 2016 年 9 月 13 日
Have you written any code so far? A simple formulation something like the following would get you the position of the dot for time t:
pos = [x0,y0] + r*[cos(theta0 + thetadot*t),sin(theta0 + thetadot*t)];
VINAY KUMAR REDDY MEDAPATI
VINAY KUMAR REDDY MEDAPATI 2016 年 9 月 13 日
編集済み: VINAY KUMAR REDDY MEDAPATI 2016 年 9 月 13 日
I tried with the following code so far. Here the dot is moving in the direction of x-axis. I want to make the dot move in a circular path.
x0 = 0;
y = 0;
v = 2; %Velocity of 2
for time=1:100
x = x0(1,:) + v*time;
plot(x, y,'r*'); %Plot the red dot
axis([0 100 0 160])
drawnow();
pause(0.1)
end

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2016 年 9 月 13 日
See if this does what you want:
crc = @(r,p,a) [r*cosd(a + p); r*sind(a + p)];
t = linspace(0, 360, 361); % Time
init_pos = 25; % Initial Position (°)
radius = 1.2;
locus = crc(radius, init_pos, t);
figure(1)
for k1 = 2:length(t)
plot(locus(1,k1), locus(2,k1), 'gp')
axis([-1.5 1.5 -1.5 1.5])
grid
axis square
drawnow
end
  9 件のコメント
Star Strider
Star Strider 2016 年 9 月 15 日
My pleasure.
It would be entirely different for square and zig-zag paths. Plotting a square and zig-zag paths I will leave to you. You may be able to adapt the circle-plotting algorithm to the square by using the cotangent function to change the radius to a straight line, considering your ‘requirements’ and constraints. A sawtooth function would be relatively easy to program, but a true zig-zag more difficult, especially if you wanted the radius of the circle to be a zig-zag.
sawtooth = @(a,p) rem(a,p).*(rem(a,p)<p);
figure(2)
plot(t, sawtooth(t,45))
grid
Maryam Naveed
Maryam Naveed 2019 年 4 月 24 日
編集済み: Maryam Naveed 2019 年 4 月 24 日
Can you further explain me this code?Actually i want 100 points that are arranged in 10 rows ans 10 columns.and each points moves in a circular path?how to do this?i will be thankful to you if u find ou=ut a solution for me.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeClassical Control Design についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by