How to make rotate the circular pattern of balls in a while loop?
3 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!