How to make rotate the circular pattern of balls in a while loop?

3 ビュー (過去 30 日間)
MSolano
MSolano 2021 年 6 月 9 日
コメント済み: Les Beckham 2021 年 6 月 11 日
Hello! I need to make the 12 balls rotate like the blue ball they don't need to have the red mark, just move at BSF frequency, I tried doing the for loop to make the 12 balls inside the while loop but it just plots a lot of balls, also tried to draw the balls with a marker 'o' but can´t do draw the 12 balls pattern
.
close all
clear
clc
clf;
% Entry Values
Nb = 12; % Number of balls
BSF = 0.222; % Frequency (Hz)
%% Data for Animation
D2 = 130;
R2 = D2/2;
d1 = 90;
d = 0.7*d1;
ang=linspace(0,2*pi,50);
xpi=R2*cos(ang);
ypi=R2*sin(ang);
patch(xpi,ypi,[0.90,0.90,0.90]); % Draw static circle
hold on
% Red mark data (Hypocycloid)
sz_mai =(d+d1)/8;
Ra = 65;
ra = 10;
ka = Ra/ra;
ka_= ka-1;
rh = 55;
ramdi = (d+d1)/4;
pmdi = plot(NaN,NaN,'-o','color', 'k', 'LineWidth', 1, 'MarkerSize', sz_mai, 'MarkerFaceColor', 'r','LineWidth', 1) ;
% Plot Balls
% Moving ball
pb = plot(NaN,NaN,'-o','color', 'k', 'LineWidth', 1, 'MarkerSize',35, 'MarkerFaceColor', 'c','LineWidth', 1) ;
% Circular Pattern
a = linspace(0,2*pi,20);
[x8,y8] = pol2cart(a,10);
fill_b=zeros(1,Nb);
h=zeros(1,Nb);
for angle = 1:Nb
h(angle) = line(x8+rh*cosd(angle/Nb*360), y8+rh*sind(angle/Nb*360) ,'color', 'k');
fill_b(angle) = fill(x8+rh*cosd(angle/Nb*360), y8+rh*sind(angle/Nb*360),[0.65,0.65,0.65]);
end
% Plot red Mark
ph = plot(NaN,NaN,'-*','LineWidth', 5, 'color', 'r','MarkerFaceColor', 'r','MarkerSize', 0.01') ;
%% Loop for Animation
tic
while (toc < 5)
hold on
% Red Mark
t = toc ;
ph.XData = [rh*cos(-2*pi*BSF*t) ra*ka_*cos(-2*pi*BSF*t) + ra*cos(ka_*2*pi*BSF*t)] ;
ph.YData = [rh*sin(-2*pi*BSF*t) ra*ka_*sin(-2*pi*BSF*t) - ra*sin(ka_*2*pi*BSF*t)] ;
% Ball
pb.XData = (rh*cos(-2*pi*BSF*t)) ;
pb.YData = (rh*sin(-2*pi*BSF*t)) ;
% 12 Gray balls
% How to introduce the frequency BSF so that the gray circles pattern
% rotates????
drawnow
end

採用された回答

Les Beckham
Les Beckham 2021 年 6 月 10 日
I think you are very close to what you want.
All I had to do to make this animate is to comment out the `hold on` line and increase the end test for the while loop (I used 50 instead of 5).
Also you probably want to add an `axis equal` command before the while loop so that your circle looks like a circle.
  4 件のコメント
MSolano
MSolano 2021 年 6 月 10 日
Yes this is it, thanks for your help. When they move the angle between each other keeps changing because the last ball doesn't move from the start point and I need the angle to be the same while moving, sorry I did not explain myself correctly.
Les Beckham
Les Beckham 2021 年 6 月 11 日
I'm glad that I was able to help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by