MATLAB: Making of a movie, rotating a circle at an input distance from centre.

rotate circle movie film imagesc

Hello
A short description of what im supposed to accomplish:
I have 2 inputs, one is for the area for the circle that is going to rotate around in the figure. The other one is for the distance this circle is to rotate compared to the centre(0,0) of the figure.
Here's what i've done so far but can't get my head around to figure out how to make it rotate around the centre at a set distance.
function rotateCircle(a,rotRad)
close all
[x,y] = meshgrid(-200:200);
circleRadius = a/pi;
radius = sqrt(circleRadius);
cx = x;
cy = y;
size(cx)
for j = 1:30
drawDisk(cx-rotRad,cy-rotRad,radius);
cx = cx + cos(j*2*pi/30);
cy = cy + sin(j*2*pi/30);
mov(j) = getframe;
end
movie(mov,10);
end
And my helpt function:
function drawDisk(cx,cy,radius)
[x,y] = meshgrid(-200:200);
circleImage = (cx).^2 + (cy).^2 < radius^2; % the disk
imagesc(x(:,1),y(:,1),circleImage);

Best Answer

I managed to solve it myself, here's the final code.
%-------------------------------
function rotateCircle(a,rotRad)
close all
circleRadius = sqrt(a/pi);
cx = 0;
cy = 0;
for j = 1:30
cx = rotRad*cos(j*2*pi/30);
cy = rotRad*sin(j*2*pi/30);
drawDisk(cx,cy,circleRadius);
mov(j) = getframe;
end
movie(mov,11,24);
end
%-------------------------------

function drawDisk(cx,cy,radius)
[x,y] = meshgrid(-200:200);
circleImage = (x-cx).^2 + (y-cy).^2 < radius^2; % the disk
imagesc(x(:,1),y(:,1),circleImage);
%-------------------------------
Related Question