MATLAB: Comment faire pivoter

Je souhaite modifier le programme suivant comme la figure suivante.
 
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
 

Meilleure réponse

  • han han, je n’ai pas eu de nouvelles de vous donc je suppose que vous avez eu du mal à adapter mes démos. J’ai donc fait la chose à 100% pour vous donner exactement ce que vous avez montré:
     

    % 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);