Rotating images after creating an image
1 view (last 30 days)
Show older comments
Make a function e91.m, that takes 2 arguments, and is called like this:
e91(a, rotRad);
it should make a movie of a disk that has area a, and is rotating around in the figure. The disk should rotate around the centre of the figure, at a distance rotRad from the centre. The function should play this video 10 times.
This has taken me about 2 hours to do. ive tried my best but i have so many mistakes! Any help would be appreciated!
cheers, i always make typos!
Have i made any huge fundamental mistakes?
clc;
[x,y] = meshgrid(-200:200);
r = 50;
cx = 200;
cy = 200;
circleImage = (x-cx).^2 + (y-cy).^2 < r^2;
imagesc(x(:,1),y(:,1),circleImage);
colormap(gray);
axis square;
xlim([-200, 200]);
ylim([-200, 200]);
axis on;
frameNumber = 1;
for angleInDegrees = 1:10:360 % Degrees
cx = 200 * cosd(angleInDegrees)
cy = 200 * sind(angleInDegrees)
circleImage = (x-cx).^2 + (y-cy).^2 < r^2;
imagesc(circleImage);
% mov(frameNumber) = getframe;
frameNumber = frameNumber + 1;
drawnow;
pause(0.2);
end
% movie(mov,10);
0 Comments
Answers (2)
Image Analyst
on 15 Jun 2013
Close, but this will get you a little closer without doing everything for you. Did you notice that cx, not cy, was being subtracted from your y? And it's better to have a loop over angle like I did it.
clc;
[x,y] = meshgrid(-200:200);
r = 50;
cx = 200;
cy = 200;
circleImage = (x-cx).^2 + (y-cx).^2 < r^2;
imagesc(x(:,1),y(:,1),circleImage);
colormap(gray);
axis square;
xlim([-200, 200]);
ylim([-200, 200]);
axis on;
frameNumber = 1;
for angleInDegrees = 1:10:360 % Degrees
cx = 200 * cosd(angleInDegrees)
cy = 200 * sind(angleInDegrees)
circleImage = (x-cx).^2 + (y-cy).^2 < r^2;
imagesc(circleImage);
% mov(frameNumber) = getframe;
frameNumber = frameNumber + 1;
drawnow;
pause(0.2);
end
% movie(mov,10);
Don't worry - there's still more for you to do and fix.
1 Comment
Image Analyst
on 15 Jun 2013
Regarding your edit. I don't feel like you're putting enough effort into your homework. I gave you that code, which does almost everything (it spins a circle around the image) and asked you to finish it but you didn't do anything except paste my code into your original question. Don't expect us to do everything for you, or else you wouldn't be handing in your solution, you'd be handing in ours. It's your homework so you must do some of it, probably the majority of it, not us.
sam
on 15 Jun 2013
Edited: sam
on 15 Jun 2013
1 Comment
Image Analyst
on 15 Jun 2013
cx and cy are the radius of the circle about which the circle moves. "r" is the radius of the circle itself - the white disc that moves.
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!