Animation of Circle angle rotation using MATLAB -
i have circle , partition circle 3 sector(120 angle each).now want increase angle 50 degree 1 part , decrease 50 degree part , keep constant third part (like 170 degree first part,70 degree second , 120 degree third).i want make animation whole process using matlab.
how can this? if have source code process using matlab, helps me much.
i draw circle , divide 3 equal sectors , polt points circle.here, attached following code:
x0=2; y0=1; r=1; teta=-pi:0.01:pi; x=r*cos(teta)+x0 y=r*sin(teta)+y0 plot(x,y) hold on scatter(x0,y0,'or') axis square %---------------------------------------- % divide circle n sectors n=3 tet=linspace(-pi,pi,n+1) xi=r*cos(tet)+x0 yi=r*sin(tet)+y0 k=1:numel(xi) plot([x0 xi(k)],[y0 yi(k)]) hold on p1=[1.5,0.4]; p2=[2,0.8]; p3=[2.5,0.2]; p4=[2.5,1]; p5=[1.5,1.6]; p6=[1.5,0.8]; p7=[2,1.2]; p8=[2,1.4]; p9=[1.6,0.7]; p10=[2.5,0.6]; p11=[2.7,0.5]; p12=[2,0.9]; p=[p1;p2;p3;p4;p5;p6;p7;p8;p9;p10;p11;p12]'; plot(p(1,:),p(2,:),'go') end
the following code produce want. simplified of code , added comments sections. parameters can set @ top. script create movie file circle_anim.mp4
can viewed outside matlab.
% set options x0 = 2; % origin x-coordinate y0 = 1; % origin y-coordinate r = 1; % radius of circle n = 3; % number of pieces m = 50; % movement of separator in radians (+acw / -cw) ts = 3; % target separator (1...n) fs = 30; % frame rate in fps t = 2; % duration in seconds s = t*fs; % movement step count % predefined points -> [x1,x2,xn;y1,y2,yn] p = [ 1.5, 2.0, 2.50, 2.5, 1.5, 1.5, 2.0, 2.0, 1.6, 2.5, 2.7, 2.0; 0.4, 0.8, 0.20, 1.0, 1.6, 0.8, 1.2, 1.4, 0.7, 0.6, 0.5, 0.9]; % calculate circle theta = -pi:0.01:pi; cirx = r*cos(theta) + x0; ciry = r*sin(theta) + y0; % initial plot figure; hold on; axis square; plot(x0,y0,'or'); % origin plot(cirx,ciry); % circle plot(p(1,:),p(2,:),'go'); % predefined points % calculate , plot separations ciro = linspace(-pi,pi,n+1); k = 1:(numel(ciro)-1) ph(k) = plot([x0,x0+r*cos(ciro(k))],[y0,y0+r*sin(ciro(k))]); %#ok<sagrow> end % vary target separator , create frames clearvars myframes; movo = linspace(ciro(ts),ciro(ts)+(m/180*pi),s); k = 1:numel(movo) set(ph(ts), 'xdata', [x0,x0+r*cos(movo(k))]); set(ph(ts), 'ydata', [y0,y0+r*sin(movo(k))]); myframes(k) = getframe; %#ok<sagrow> end % write frames video mymovie = videowriter('circle_anim.mp4','mpeg-4'); mymovie.framerate = fs; open(mymovie); k = 1:length(myframes) writevideo(mymovie,myframes(k)); end close(mymovie);
Comments
Post a Comment