How to rotate?

8 views (last 30 days)
han han
han han on 30 May 2020
Edited: han han on 30 May 2020
I want to modify the following program like the following figure.
a=0.5;
b=2;
m = 1000;
x = zeros(m,1);
y = zeros(m,1);
theta = linspace(0,2*pi,m);
for k = 1:m
x(k) = a * cos(theta(k));
y(k) = b * sin(theta(k));
end
for a=0:0.5:1
for xc = 1:-1:0
R = [cos(a) -sin(a); ...
sin(a) cos(a)];
rCoords = R*[x' ; y'];
xr = rCoords(1,:)';
yr = rCoords(2,:)';
yc = 1;
grid on;
axis equal;
end
hold on
plot(xr+xc,yr+yc,'b');
end
  1 Comment
Ameer Hamza
Ameer Hamza on 30 May 2020
The pasted code in incomplete.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 30 May 2020
han han, I have not heard back from you so I assume you had trouble adapting my demos. So I did the thing 100% for you to give you exactly what you showed:
% Demo to rotate an ellipse about a center that also rotates around a circle.
% By ImageAnalyst
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
xCenter = 23.5;
yCenter = 0.5;
a = 2.0;
b = 0.5;
r = a;
% First get an ellipse centered at the origin of the proper size and shape.
hEllipse = imellipse(gca,[-a, -b, 2*a, 2*b]); % Second argument defines ellipse shape and position.
% Get (x,y) coordinates from the ellipse.
disp(hEllipse);
xy = hEllipse.getVertices();
% Clear original ellipse from axes.
axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
x = xy(:,1);
y = xy(:,2);
% plot(x, y, 'r-');
xy = [x y];
% Now rotate the ellipse through other angles and centers.
angles = 0 : 22.5 : 360 - 22.5;
for k = 1 : length(angles)
theta = angles(k);
rotationArray = [cosd(theta) sind(theta); -sind(theta) cosd(theta)];
% Make a rotated ellipse about the origin.
rotated_xy = xy * rotationArray;
% Now shift its center.
xCenter2 = xCenter + (r - 0.25) * cosd(theta);
yCenter2 = yCenter + (r - 0.25) * sind(theta);
x = rotated_xy(:,1) + xCenter2;
y = rotated_xy(:,2) + yCenter2;
% Now plot the rotated ellipse.
plot(x, y, 'color', 'b', 'LineWidth', 2);
if k == 1
axis square;
grid on;
hold on;
end
end
title('Demo Specially Made for han han', 'FontSize', 30);
If this does what you want, can you Accept this answer (since it seems no one else is going to offer a different working solution). Thanks in advance.
  1 Comment
han han
han han on 30 May 2020
Edited: han han on 30 May 2020
wow.... it's a amazing
Thank U so much!!!

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 30 May 2020
See my attached demos.

Categories

Find more on Argument Definitions 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!